There seems to be no way to access grunt’s this.async() from within onComplete. See this stackoverflow question.
I know that in the case of that question, fs.writeFileSync() is a workaround or using grunt.file.write() is more correct. But the user may want to
Call some other async API for which there is no synchronous alternative.
Have a way for the search task to wait for the completion before continuing (i.e., I know I can start a Promise() in the callback—which keeps node from exiting before the operation completes. But there’s no way to make the launched task wait right now and you might be launching tasks using grunt’s API rather than the CLI and want to know that when the task completes all of the assets generated by the task are fully written to disk).
IMO, all of the callbacks should just have their return value evaluated by Promise.resolve(). This would work with existing synchronous callbacks and magically support Promises whenever callbacks opt in by returning Promises.
There seems to be no way to access grunt’s
this.async()
from withinonComplete
. See this stackoverflow question.I know that in the case of that question,
fs.writeFileSync()
is a workaround or usinggrunt.file.write()
is more correct. But the user may want toIMO, all of the callbacks should just have their return value evaluated by
Promise.resolve()
. This would work with existing synchronous callbacks and magically support Promises whenever callbacks opt in by returning Promises.