diff --git a/core/src/runtime.rs b/core/src/runtime.rs index 8dbe1440..f942ecff 100644 --- a/core/src/runtime.rs +++ b/core/src/runtime.rs @@ -5,6 +5,13 @@ pub(crate) mod raw; mod base; pub use base::{Runtime, WeakRuntime}; +/// The type of the interrupt handler. +#[cfg(not(feature = "parallel"))] +pub type InterruptHandler = Box bool + 'static>; +/// The type of the interrupt handler. +#[cfg(feature = "parallel")] +pub type InterruptHandler = Box bool + Send + 'static>; + #[cfg(feature = "futures")] mod r#async; #[cfg(feature = "futures")] diff --git a/core/src/runtime/async.rs b/core/src/runtime/async.rs index 18060e18..46249e7e 100644 --- a/core/src/runtime/async.rs +++ b/core/src/runtime/async.rs @@ -11,12 +11,15 @@ use async_lock::Mutex; use crate::allocator::Allocator; #[cfg(feature = "loader")] use crate::loader::{RawLoader, Resolver}; -use crate::{context::AsyncContext, result::AsyncJobException, Ctx, Error, Exception, Result}; +use crate::{ + context::AsyncContext, markers::ParallelSend, result::AsyncJobException, Ctx, Error, Exception, + Result, +}; use super::{ raw::{Opaque, RawRuntime}, spawner::DriveFuture, - MemoryUsage, + InterruptHandler, MemoryUsage, }; #[derive(Clone)] @@ -91,7 +94,7 @@ impl AsyncRuntime { /// If the provided closure returns `true` the interpreter will raise and uncatchable /// exception and return control flow to the caller. #[inline] - pub async fn set_interrupt_handler(&self, handler: Option bool + 'static>>) { + pub async fn set_interrupt_handler(&self, handler: Option) { unsafe { self.inner.lock().await.set_interrupt_handler(handler); } diff --git a/core/src/runtime/base.rs b/core/src/runtime/base.rs index 93bbad32..5a69a19f 100644 --- a/core/src/runtime/base.rs +++ b/core/src/runtime/base.rs @@ -10,7 +10,7 @@ use crate::allocator::Allocator; use super::{ raw::{Opaque, RawRuntime}, - MemoryUsage, + InterruptHandler, MemoryUsage, }; /// A weak handle to the runtime. @@ -72,7 +72,7 @@ impl Runtime { /// If the provided closure returns `true` the interpreter will raise and uncatchable /// exception and return control flow to the caller. #[inline] - pub fn set_interrupt_handler(&self, handler: Option bool + 'static>>) { + pub fn set_interrupt_handler(&self, handler: Option) { unsafe { self.inner.lock().set_interrupt_handler(handler); } diff --git a/core/src/runtime/raw.rs b/core/src/runtime/raw.rs index ec842e29..f2bc6d63 100644 --- a/core/src/runtime/raw.rs +++ b/core/src/runtime/raw.rs @@ -11,6 +11,7 @@ use crate::{qjs, Function}; #[cfg(feature = "futures")] use super::spawner::Spawner; +use super::InterruptHandler; /// Opaque book keeping data for rust. pub(crate) struct Opaque<'js> { @@ -18,7 +19,7 @@ pub(crate) struct Opaque<'js> { pub panic: Option>, /// The user provided interrupt handler, if any. - pub interrupt_handler: Option bool + 'static>>, + pub interrupt_handler: Option, #[cfg(feature = "futures")] pub spawner: Option>, @@ -233,10 +234,7 @@ impl RawRuntime { /// Set a closure which is regularly called by the engine when it is executing code. /// If the provided closure returns `true` the interpreter will raise and uncatchable /// exception and return control flow to the caller. - pub unsafe fn set_interrupt_handler( - &mut self, - handler: Option bool + 'static>>, - ) { + pub unsafe fn set_interrupt_handler(&mut self, handler: Option) { unsafe extern "C" fn interrupt_handler_trampoline( _rt: *mut qjs::JSRuntime, opaque: *mut ::std::os::raw::c_void,