Now that Webtask runs on Node 8 and supports async/await (see https://github.com/auth0/webtask-bundle/issues/23), it would be nice to support webtasks that returned promises instead of calling callbacks.
However this has the following disadvantages compared to my ideal:
Control flow: you have to call the callback every time you want to "return" rather than just using return. And every time you do so you have to pass null as the first parameter to the callback.
Error handling: if code throws an exception, that exception will not be forwarded to the cb, it'll just be uncaught. By contrast, in the first example, if the webtask rejected with an error e, that would be equivalent to the webtask having called cb(e).
Drawbacks
I am aware that when webtasks accept only a single parameter, that parameter is assumed to be the callback not the context (see here), so my proposal would be a breaking change.
Now that Webtask runs on Node 8 and supports
async/await
(see https://github.com/auth0/webtask-bundle/issues/23), it would be nice to support webtasks that returned promises instead of calling callbacks.The ideal
Such a webtask would ideally look like
The status quo
The above would be equivalent to
The compromise
I am aware that you can currently use
await
within webtasks, so long as you call the callback, likeHowever this has the following disadvantages compared to my ideal:
return
. And every time you do so you have to passnull
as the first parameter to the callback.cb
, it'll just be uncaught. By contrast, in the first example, if the webtask rejected with an errore
, that would be equivalent to the webtask having calledcb(e)
.Drawbacks
I am aware that when webtasks accept only a single parameter, that parameter is assumed to be the callback not the context (see here), so my proposal would be a breaking change.