Bug 1391707: Part 0 - Remove Task.jsm support from DeferredTask. r?florian
MozReview-Commit-ID: LEbrPt0uae0
--- 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);
}
},
};