summaryrefslogtreecommitdiff
path: root/ext/ffi/callback.rs
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2023-07-30 16:43:22 +0300
committerGitHub <noreply@github.com>2023-07-30 16:43:22 +0300
commite348c11b64410cf91bd5925ffbc5a9009947a80f (patch)
treeb7087ced0e6ac6ec405e58728024196c12c29597 /ext/ffi/callback.rs
parentee7f36afdb60084203a31455f327672fbff6d9aa (diff)
perf(ext/ffi): Avoid receiving on FFI async work channel when no UnsafeCallback exists (#19454)
Diffstat (limited to 'ext/ffi/callback.rs')
-rw-r--r--ext/ffi/callback.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/ext/ffi/callback.rs b/ext/ffi/callback.rs
index 78a21ab8f..e9d91855d 100644
--- a/ext/ffi/callback.rs
+++ b/ext/ffi/callback.rs
@@ -567,7 +567,19 @@ where
}
let async_work_sender =
- state.borrow_mut::<FfiState>().async_work_sender.clone();
+ if let Some(ffi_state) = state.try_borrow_mut::<FfiState>() {
+ ffi_state.async_work_sender.clone()
+ } else {
+ let (async_work_sender, async_work_receiver) =
+ mpsc::unbounded::<PendingFfiAsyncWork>();
+
+ state.put(FfiState {
+ async_work_receiver,
+ async_work_sender: async_work_sender.clone(),
+ });
+
+ async_work_sender
+ };
let callback = v8::Global::new(scope, cb).into_raw();
let current_context = scope.get_current_context();
let context = v8::Global::new(scope, current_context).into_raw();