emscripten-core / emscripten-core/emscripten

Allow propagating errors from Asyncified imports back to C++

Open
#11,434 3 comments 1 reaction 0 assignees View on GitHub
asyncify
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Right now, from what I understand, there is no way to wake up the C++ side with an error instead of a successful value. This makes errors in Asyncified functions behave differently than in regular imports in that, upon an async error, the C++ code can never be resumed, and such error has no chance of getting handled, and instead only ends up being printed to the Console.

This is not very important for wakeUp based handler, but in promises rejections are fairly common, and would be good to propagate those somehow back to C++.

I'd imagine following Promise's design here might be easy enough; basically, they have a `resolve` and `reject` callbacks, and are guaranteed that whatever is called first, wins, and no further resolution/rejection occurs.

As far as I can tell, `wakeUp` is a direct analogy for the `resolve` callback, so I'd imagine we could simply extend API to accept a `reject` callback as well, store it on the state, and on C++ side it would call `throw` instead of continuing execution.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.