feat(napi): add ThreadsafeFunction::call_async_catch to handle errors in callback functions#3291
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (6)
📝 WalkthroughWalkthroughAdds a unified async API ChangesThreadsafeFunction call_async_catch
Sequence DiagramsequenceDiagram
participant Caller
participant call_async_catch
participant WithCallback
participant OneshotReceiver
participant JS_Callback
Caller->>call_async_catch: enqueue call with value
call_async_catch->>WithCallback: schedule TSFN call with oneshot sender
WithCallback->>JS_Callback: invoke JS callback
alt JS throws
JS_Callback-->>WithCallback: throw
WithCallback->>OneshotReceiver: send Err(PendingException)
else JS returns
JS_Callback-->>WithCallback: return value
WithCallback->>OneshotReceiver: send Ok(Return)
end
call_async_catch->>OneshotReceiver: await result
OneshotReceiver-->>call_async_catch: Result<Return>
call_async_catch-->>Caller: Result<Return>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…rs in callback functions
b61561f to
d9f062f
Compare
|
@codex review |
ThreadsafeFunction::call_async_catch to handle errors in callback functionsThreadsafeFunction::call_async_catch to handle errors in callback functions
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Use `ThreadsafeFunction::call_async_catch` added in napi-rs/napi-rs#3291 so that we don't have to wrap values in promise on JS side. refs #5931, #9355
Use `ThreadsafeFunction::call_async_catch` added in napi-rs/napi-rs#3291 so that we don't have to wrap values in promise on JS side. refs #5931, #9355
When a
ThreadsafeFunctionis parameterized withCalleeHandled = falseand its JavaScript callback throws, callingtsfn.call_async(value).awaitdoes not surface the error to the awaiter and it terminates the host process withfatal runtime error: failed to initiate panic, error 5(#2812). While this is an expected behavior, it is tedious to convert the callback to always receive a promise (rolldown/rolldown#9355) so that it doesn't cause a panic.I did not change the behavior of
call_asyncin this PR as you mentioned that it is an intentional behavior. Instead I addedcall_async_catchmethod.Summary by CodeRabbit
New Features
Tests
Examples