use threadpool::ThreadPool; use crate::{Env, Result, Value, ValueType}; pub struct NapiRSThreadPool(pub ThreadPool); unsafe impl Send for NapiRSThreadPool {} unsafe impl Sync for NapiRSThreadPool {} pub trait Task { type Output: Send + 'static; type JsValue: ValueType; fn compute(&mut self) -> Result; fn resolve(&self, env: &mut Env, output: Self::Output) -> Result>; } pub struct ThreadSafeTask(pub *mut T); impl ThreadSafeTask { pub fn new(task: T) -> ThreadSafeTask { ThreadSafeTask(Box::into_raw(Box::new(task))) } #[inline] pub fn borrow(&self) -> &'static mut T { Box::leak(unsafe { Box::from_raw(self.0) }) } } impl Drop for ThreadSafeTask { fn drop(&mut self) { unsafe { Box::from_raw(self.0) }; } } unsafe impl Send for ThreadSafeTask {} unsafe impl Sync for ThreadSafeTask {}