You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using coro 1.0.3, promises 1.2.0.1, and future 1.28.0, I get the following unexpected behavior. Running the following code, the error is raised in the main thread (and not handled by the onRejected error handler, the execution does not reach the part of the code that defines the handlers):
The same goes if I have some await statement after stop(.). Of course, if I await a promise before the stop(.) all goes well.
It seems to me that whatever compiles this down to promises makes the first block of synchronous instructions execute immediately, which is also how things are implemented in other languages/execution environments (NodeJS for instance).
However, everything that happens inside an asynchronous function should be handled by declared handlers, and eventually, if some errors are not handled those should raise some warnings about unhandled rejections.
I am not sure if that should also be the case for promises as defined in the promises package, and maybe that is where the error originates from. In JavaScript for example, they have made the decision to also nicely handle direct errors raised within a Promise executor function (although one could argue the only proper way to raise an error for a promise in JavaScript is to call the reject handler).
The text was updated successfully, but these errors were encountered:
king-of-poppk
changed the title
Executing an async function should always return a promise immediately
Async function errors should not be raised in the main thread
Jun 16, 2023
Using
coro
1.0.3,promises
1.2.0.1, andfuture
1.28.0, I get the following unexpected behavior. Running the following code, the error is raised in the main thread (and not handled by theonRejected
error handler, the execution does not reach the part of the code that defines the handlers):The same goes if I have some await statement after
stop(.)
. Of course, if I await a promise before thestop(.)
all goes well.It seems to me that whatever compiles this down to promises makes the first block of synchronous instructions execute immediately, which is also how things are implemented in other languages/execution environments (NodeJS for instance).
However, everything that happens inside an asynchronous function should be handled by declared handlers, and eventually, if some errors are not handled those should raise some warnings about unhandled rejections.
I am not sure if that should also be the case for promises as defined in the
promises
package, and maybe that is where the error originates from. In JavaScript for example, they have made the decision to also nicely handle direct errors raised within aPromise
executor function (although one could argue the only proper way to raise an error for a promise in JavaScript is to call thereject
handler).The text was updated successfully, but these errors were encountered: