Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async function errors should not be raised in the main thread #39

Open
king-of-poppk opened this issue Jun 16, 2023 · 1 comment
Open

Comments

@king-of-poppk
Copy link

king-of-poppk commented Jun 16, 2023

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):

f <- async(\() {
  stop(":(")
})

p <- f()

p %>% then(
  onFullfilled = \(value) { print(value) },
  onRejected = \(error) { print(error$message) }
)

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).

@king-of-poppk

This comment was marked as outdated.

@king-of-poppk 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant