Bug 1391707: Part 0 - Remove Task.jsm support from DeferredTask. r?florian draft
authorKris Maglione <maglione.k@gmail.com>
Sun, 10 Sep 2017 13:14:12 -0700 (2017-09-10)
changeset 662050 af5e8e34381bb52e1136bb3ac5d974931ad7c58d
parent 657212 2bf1d0e361ab1ad935b61796520b118064d33a39
child 662051 c95267aff7fba0d920c4585d8fcb93757f3c86d8
push id78936
push usermaglione.k@gmail.com
push dateSun, 10 Sep 2017 20:18:54 +0000 (2017-09-10)
reviewersflorian
bugs1391707
milestone57.0a1
Bug 1391707: Part 0 - Remove Task.jsm support from DeferredTask. r?florian MozReview-Commit-ID: LEbrPt0uae0
toolkit/modules/DeferredTask.jsm
--- a/toolkit/modules/DeferredTask.jsm
+++ b/toolkit/modules/DeferredTask.jsm
@@ -85,41 +85,43 @@ this.EXPORTED_SYMBOLS = [
 // Globals
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
                                   "resource://gre/modules/PromiseUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "Task",
-                                  "resource://gre/modules/Task.jsm");
 
 const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer",
                                      "initWithCallback");
 
 // DeferredTask
 
 /**
  * Sets up a task whose execution can be triggered after a delay.
  *
  * @param aTaskFn
- *        Function or generator function to execute.  This argument is passed to
- *        the "Task.spawn" method every time the task should be executed.  This
+ *        Function to execute.  If the function returns a promise, the task is
+ *        not considered complete until that promise resolves.  This
  *        task is never re-entered while running.
  * @param aDelayMs
  *        Time between executions, in milliseconds.  Multiple attempts to run
  *        the task before the delay has passed are coalesced.  This time of
  *        inactivity is guaranteed to pass between multiple executions of the
  *        task, except on finalization, when the task may restart immediately
  *        after the previous execution finished.
  */
 this.DeferredTask = function(aTaskFn, aDelayMs) {
   this._taskFn = aTaskFn;
   this._delayMs = aDelayMs;
+
+  if (aTaskFn.isGenerator()) {
+    Cu.reportError(new Error(`Unexpected generator function passed to DeferredTask`));
+  }
 }
 
 this.DeferredTask.prototype = {
   /**
    * Function or generator function to execute.
    */
   _taskFn: null,
 
@@ -296,19 +298,14 @@ this.DeferredTask.prototype = {
     })().catch(Cu.reportError));
   },
 
   /**
    * Executes the associated task and catches exceptions.
    */
   async _runTask() {
     try {
-      let result = this._taskFn();
-      if (Object.prototype.toString.call(result) == "[object Generator]") {
-        await Task.spawn(result); // eslint-disable-line mozilla/no-task
-      } else {
-        await result;
-      }
+      await this._taskFn();
     } catch (ex) {
       Cu.reportError(ex);
     }
   },
 };