From 00f4521b205bf25c79f0fa7c9a6840941342bda4 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Tue, 28 Jun 2022 12:23:36 +0300 Subject: feat(ext/ffi): Thread safe callbacks (#14942) --- core/extensions.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/extensions.rs') diff --git a/core/extensions.rs b/core/extensions.rs index 682987124..ce6957875 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -1,13 +1,13 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::OpState; use anyhow::Error; -use std::task::Context; +use std::{cell::RefCell, rc::Rc, task::Context}; pub type SourcePair = (&'static str, &'static str); pub type OpFnRef = v8::FunctionCallback; pub type OpMiddlewareFn = dyn Fn(OpDecl) -> OpDecl; pub type OpStateFn = dyn Fn(&mut OpState) -> Result<(), Error>; -pub type OpEventLoopFn = dyn Fn(&mut OpState, &mut Context) -> bool; +pub type OpEventLoopFn = dyn Fn(Rc>, &mut Context) -> bool; #[derive(Clone, Copy)] pub struct OpDecl { @@ -90,13 +90,13 @@ impl Extension { pub fn run_event_loop_middleware( &self, - op_state: &mut OpState, + op_state_rc: Rc>, cx: &mut Context, ) -> bool { self .event_loop_middleware .as_ref() - .map(|f| f(op_state, cx)) + .map(|f| f(op_state_rc, cx)) .unwrap_or(false) } @@ -148,7 +148,7 @@ impl ExtensionBuilder { pub fn event_loop_middleware(&mut self, middleware_fn: F) -> &mut Self where - F: Fn(&mut OpState, &mut Context) -> bool + 'static, + F: Fn(Rc>, &mut Context) -> bool + 'static, { self.event_loop_middleware = Some(Box::new(middleware_fn)); self -- cgit v1.2.3