Add `queue.drain` method

master
Sven Slootweg 8 years ago
parent 9514f5db8d
commit d90d11ce3c

@ -118,6 +118,12 @@ Adds a task to the queue for the given `type`.
Note that this function will __return a Promise__, passing through the result from the task handler. If the Promise from the task handler resolves, then the one returned from this function will resolve with the same value. If the Promise from the task handler is rejected, this one will also reject, with the same error.
### queue.drain(type)
Drains (ie. empties) the queue for the given `type`. Note that this __will not__ try to stop or 'cancel' *running* tasks; it will simply remove the *upcoming* tasks that are still in the queue.
* __type__: The name of the task type, as specified in `queue.define`.
### queue.awaitDrained(type)
Returns a Promise that will resolve when the task queue has run out of tasks for a given `type`. Some of the previously queued tasks may still be running, however - this simply signals that there are no *upcoming* tasks scheduled anymore.

@ -177,6 +177,14 @@ module.exports = function createTaskQueue(options) {
return deferredPromise;
});
},
drain: function drain(type) {
if (handlers[type] == null) {
throw new TaskQueueError("No such task type exists.");
}
debugTasks("Draining tasks for '" + type + "'");
tasks[type] = [];
},
awaitDrained: function awaitDrained(type) {
var _this = this;

@ -176,6 +176,14 @@ module.exports = function createTaskQueue(options) {
return deferredPromise;
})
},
drain: function(type) {
if (handlers[type] == null) {
throw new TaskQueueError("No such task type exists.")
}
debugTasks(`Draining tasks for '${type}'`);
tasks[type] = [];
},
awaitDrained: function(type) {
return Promise.try(() => {
if (handlers[type] == null) {

Loading…
Cancel
Save