-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
V3: Added JsCallable #9813
Merged
Merged
V3: Added JsCallable #9813
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yamadapc
suggested changes
Jun 20, 2024
yamadapc
reviewed
Jun 20, 2024
yamadapc
reviewed
Jun 21, 2024
crates/node-bindings/src/helpers/js_callable/local_functions.rs
Outdated
Show resolved
Hide resolved
…e to catch running functions on the main thread (to error on deadlock)
alshdavid
force-pushed
the
alsh/js-callable
branch
from
June 21, 2024 01:55
0cd9695
to
90c6ae6
Compare
yamadapc
suggested changes
Jun 21, 2024
yamadapc
approved these changes
Jun 21, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added
JsCallable
utility to simplify the usage of napi JavaScript functions from Rust.These must be run in their own thread. This works with async functions, sync functions, and promises.
Please leave your thoughts and comments 🙏
Usage
Or with the
FileSystemNapi
wrapperBefore / After hooks
The
call
andcall_with_return
methods take mapping functions to let you cast Rust types to napi types and back. This is useful if you need to supply a callback as a parameter or do some custom deserialization logic (often needed for enums)Mappers
Included are helper functions
map_params_serde
andmap_return_serde
which handle the type conversion automatically using serde