grunt icon indicating copy to clipboard operation
grunt copied to clipboard

allow the specification of a callback in Task#run

Open toastynerd opened this issue 10 years ago • 1 comments

An attempt at https://github.com/gruntjs/grunt/issues/1184, really it just pulls out a callback from the run function and uses it for done(). The issue is old and I didn't see an official response so I thought I would take a stab at it.

toastynerd avatar Jan 29 '15 21:01 toastynerd

+1 this.

I rarely need to use the callback function, but on certain complex projects it's necessary. Anyone wanting to use this without overwriting the source can use this prototype:

grunt.util.task.Task.prototype.run = function () {
    if (typeof(arguments[arguments.length - 1]) === 'function') {
        this._options.done = arguments[arguments.length - 1];
        delete arguments[arguments.length - 1];
    }
    var things = this.parseArgs(arguments).map(this._taskPlusArgs, this);
    var fails = things.filter(function(thing) { return !thing.task; });
    if (fails.length > 0) {
        this._throwIfRunning(new Error('Task "' + fails[0].nameArgs + '" not found.'));
        return this;
    }
    this._push(things);
    return this;
}

nikolowry avatar Aug 14 '15 01:08 nikolowry