grunt icon indicating copy to clipboard operation
grunt copied to clipboard

Request: have grunt automatically enter async mode if task returns a promise

Open elliot-nelson opened this issue 6 years ago • 1 comments
trafficstars

Every grunt task I've ever seen looks, essentially, like this:

grunt.registerTask('build', function () {
    const done = this.async();

    callSomeModule()
    .then(() => done())
    .catch(error => {
        grunt.fail.warn(error);
        done(false);
    });
});

It would be nice if by default, grunt recognized a Promise return value and did the boilerplate for you (spitting a stack trace to warn if the promise is rejected, continuing if the promise resolved).

I'd be open to to putting up a tentative PR, if this sounds like something that could be added.

Example desired syntax:

grunt.registerTask('build', function () {
    return callSomeModule();
});

elliot-nelson avatar Mar 09 '19 14:03 elliot-nelson

similarly it would be awesome to support this syntax:

grunt.registerTask('build', async function () {
    await callSomeModule();
});

davidalpert avatar Aug 14 '22 18:08 davidalpert