[rygel] core: Don't wait for item when there is no need to



commit 8d5ea10ea798311fbdb7a2446a54081b3f1ea1b2
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Mon Dec 13 18:59:41 2010 +0200

    core: Don't wait for item when there is no need to
    
    The 'updated' signal from the container could be emitted 'before' we start
    to wait for it so better first check if item is already there and then
    wait if its not.

 src/rygel/rygel-item-creator.vala |   29 +++++++++++++++--------------
 1 files changed, 15 insertions(+), 14 deletions(-)
---
diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala
index 081aa09..bc6d927 100644
--- a/src/rygel/rygel-item-creator.vala
+++ b/src/rygel/rygel-item-creator.vala
@@ -291,29 +291,30 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine {
     private async void wait_for_item (WritableContainer container) {
         debug ("Waiting for new item to appear under container '%s'..",
                container.id);
-        var not_added = true;
 
-        while (not_added) {
-            var id = container.container_updated.connect ((container) => {
-                this.wait_for_item.callback ();
-            });
-
-            yield;
-
-            container.disconnect (id);
+        MediaItem item = null;
 
+        while (item == null) {
             try {
-                var item = yield container.find_object (this.item.id,
-                                                        this.cancellable);
-                if (item != null) {
-                    not_added = false;
-                }
+                item = yield container.find_object (this.item.id,
+                                                    this.cancellable)
+                       as MediaItem;
             } catch (Error error) {
                 warning ("Error from container '%s' on trying to find newly " +
                          "added child item '%s' in it",
                          container.id,
                          this.item.id);
             }
+
+            if (item == null) {
+                var id = container.container_updated.connect ((container) => {
+                    this.wait_for_item.callback ();
+                });
+
+                yield;
+
+                container.disconnect (id);
+            }
         }
         debug ("Finished waiting for new item to appear under container '%s'",
                container.id);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]