[Pkg-mozext-commits] [tabmixplus] 52/147: Avoid using AsyncUtils.defer

David Prévot taffit at moszumanska.debian.org
Sat Aug 5 15:27:36 UTC 2017


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository tabmixplus.

commit 9bac8b517d23e7b2f7dcf971efb862d9a4e71de8
Author: onemen <tabmix.onemen at gmail.com>
Date:   Tue Dec 6 22:24:54 2016 +0200

    Avoid using AsyncUtils.defer
---
 modules/AsyncUtils.jsm | 48 ++++++++++++++++++------------------------------
 1 file changed, 18 insertions(+), 30 deletions(-)

diff --git a/modules/AsyncUtils.jsm b/modules/AsyncUtils.jsm
index 5e09d87..41c4765 100644
--- a/modules/AsyncUtils.jsm
+++ b/modules/AsyncUtils.jsm
@@ -10,11 +10,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Promise",
   "resource://gre/modules/Promise.jsm");
 
 this.AsyncUtils = {
-  /* PromiseUtils.defer exist since Firefox 39 */
-  defer: function() {
-    return new Deferred();
-  },
-
   spawnFn: function(thisArg, fn, index) {
     return this.promisify(thisArg, fn, index)();
   },
@@ -24,31 +19,24 @@ this.AsyncUtils = {
   },
 
   promisify: function(thisArg, fn, index) {
-    return function() {
-      let deferred = new Deferred();
-      let args = Array.prototype.slice.call(arguments);
-      if (typeof index == "undefined")
-        index = args.length;
-      args.splice(index, 0, deferred.callback);
-
-      try {
-        fn.apply(thisArg, args);
-      } catch (ex) {
-        deferred.reject(ex);
-      }
-      return deferred.promise;
+    return function(...args) {
+      return new Promise((resolve, reject) => {
+        if (typeof index == "undefined")
+          index = args.length;
+        args.splice(index, 0, (result, error) => {
+          if (error) {
+            reject(error);
+          } else {
+            resolve(result);
+          }
+        });
+
+        try {
+          fn.apply(thisArg, args);
+        } catch (ex) {
+          reject(ex);
+        }
+      });
     };
   }
 };
-
-function Deferred() {
-  let defer = Promise.defer();
-  this.promise = defer.promise;
-  this.resolve = defer.resolve;
-  this.reject = defer.reject;
-  this.callback = (result, error) => {
-    if (error)
-      return this.reject(error);
-    return this.resolve(result);
-  };
-}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/tabmixplus.git



More information about the Pkg-mozext-commits mailing list