Commits

sunhaitao committed 20eed31

Added experimental asynchronous calling support.

Comments (0)

Files changed (2)

Extension/chrome/content/Conductory.js

       alert("Hello, " + obj() + "!");
     };
 
-    this.book = function (/* demandList */) {
-      var demandList = arguments;
+    this.book = function (/* ...demandList, callback */) {
+      var demandList = [], callback, asynchronously = false;
+
+      var last = 0;
+      for (; last < arguments.length - 1; last++) {
+          demandList.push(arguments[last]);
+      }
+      if (typeof arguments[last] == 'function') {
+        callback = arguments[last];
+        asynchronously = true;
+      } else {
+        demandList.push(arguments[last]);
+      }
+
       var requestList = [];
       for each (demand in demandList) {
         if (demand.protocol == undefined) {
         }
         requestList.push(request);
       }
+
       var reserveList = [];
       window.openDialog(
         "chrome://conductory/content/device-picker.xul",
         "",
-        "modal",
-        requestList,
+        asynchronously ? "" : "modal",
+        {"requestList":requestList, "callback":callback},
         reserveList
       );
-      return reserveList;
+      return asynchronously ? undefined : reserveList;
     };
   };
 

Extension/chrome/content/device-picker.js

   return document.createTextNode(content);
 }
 
-var requestList = arguments[0];
+var callback = arguments[0]["callback"];
+var requestList = arguments[0]["requestList"];
 var reserveList = arguments[1];
 
 function makeDeviceItem(request) {
     }
   }
   window.close();
+  if (callback != undefined) {
+    callback.apply(null, reserveList);
+  }
 }