summaryrefslogtreecommitdiff
path: root/ext/ffi/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ffi/lib.rs')
-rw-r--r--ext/ffi/lib.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index ccad69d73..2d3bb2866 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -114,14 +114,6 @@ deno_core::extension!(deno_ffi,
state = |state, options| {
// Stolen from deno_webgpu, is there a better option?
state.put(Unstable(options.unstable));
-
- let (async_work_sender, async_work_receiver) =
- mpsc::unbounded::<PendingFfiAsyncWork>();
-
- state.put(FfiState {
- async_work_receiver,
- async_work_sender,
- });
},
event_loop_middleware = event_loop_middleware,
);
@@ -133,11 +125,10 @@ fn event_loop_middleware(
// FFI callbacks coming in from other threads will call in and get queued.
let mut maybe_scheduling = false;
- let mut work_items: Vec<PendingFfiAsyncWork> = vec![];
-
- {
- let mut op_state = op_state_rc.borrow_mut();
- let ffi_state = op_state.borrow_mut::<FfiState>();
+ let mut op_state = op_state_rc.borrow_mut();
+ if let Some(ffi_state) = op_state.try_borrow_mut::<FfiState>() {
+ // TODO(mmastrac): This should be a SmallVec to avoid allocations in most cases
+ let mut work_items = Vec::with_capacity(1);
while let Ok(Some(async_work_fut)) =
ffi_state.async_work_receiver.try_next()
@@ -147,10 +138,11 @@ fn event_loop_middleware(
maybe_scheduling = true;
}
+ // Drop the op_state and ffi_state borrows
drop(op_state);
- }
- while let Some(async_work_fut) = work_items.pop() {
- async_work_fut();
+ for async_work_fut in work_items.into_iter() {
+ async_work_fut();
+ }
}
maybe_scheduling