Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow the specification of a callback in Task#run #1281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/util/task.js
Expand Up @@ -171,6 +171,11 @@

// Enqueue a task.
Task.prototype.run = function() {
// pull out a callback then parse arguments as normal
if (typeof(arguments[arguments.length - 1]) === 'function') {
this._options.done = arguments[arguments.length - 1];
delete arguments[arguments.length - 1];
}
// Parse arguments into an array, returning an array of task+args objects.
var things = this.parseArgs(arguments).map(this._taskPlusArgs, this);
// Throw an exception if any tasks weren't found.
Expand Down
11 changes: 11 additions & 0 deletions test/util/task_test.js
Expand Up @@ -278,6 +278,17 @@ exports['Tasks'] = {
});
task.run('a', 'h').start();
},
'Task#run (callback)': function(test) {
test.expect(2);
var task = this.task;
task.registerTask('a', 'Push task name onto result and run other tasks', function() { result.push(this.name); task.run('b'); delay(this.async()); });
task.registerTask('b', 'Push task onto result', result.pushTaskname);
task.run('a', function() {
test.strictEqual(result.getJoined(), 'ab', 'Tasks should run in order');
test.strictEqual(true, true, 'this call back should be run when the task is finished');
test.done();
}).start();
},
'Task#current': function(test) {
test.expect(8);
var task = this.task;
Expand Down