Bug 1495387 - introduce async front instantiation; r=ochameau
authoryulia <ystartsev@mozilla.com>
Thu, 18 Oct 2018 14:34:33 +0000
changeset 490315 a6b4461eadf0622f4d4f6ea1ee8389d1c655b336
parent 490314 3a70a65a75cf9bf30152ebd0e69ccbde3a913f00
child 490316 a58112b87de672f400dc5d23ad8bac80d292a2fd
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersochameau
bugs1495387
milestone64.0a1
Bug 1495387 - introduce async front instantiation; r=ochameau Depends on D8989 Differential Revision: https://phabricator.services.mozilla.com/D8990
devtools/shared/protocol.js
--- a/devtools/shared/protocol.js
+++ b/devtools/shared/protocol.js
@@ -1599,17 +1599,23 @@ var generateRequestMethods = function(ac
  * @param object proto
  *    The object prototype.  Must have a 'typeName' property,
  *    should have method definitions, can have event definitions.
  */
 var FrontClassWithSpec = function(actorSpec, frontProto) {
   // Existing Fronts are relying on the initialize instead of constructor methods.
   const cls = function() {
     const instance = Object.create(cls.prototype);
-    instance.initialize.apply(instance, arguments);
+    const initializer = instance.initialize.apply(instance, arguments);
+
+    // Async Initialization
+    // return a promise that resolves with the instance if the initializer is async
+    if (initializer && typeof initializer.then === "function") {
+      return initializer.then(resolve => instance);
+    }
     return instance;
   };
   cls.prototype = extend(Front.prototype, generateRequestMethods(actorSpec, frontProto));
 
   if (!registeredTypes.has(actorSpec.typeName)) {
     types.addActorType(actorSpec.typeName);
   }
   registeredTypes.get(actorSpec.typeName).frontClass = cls;