From 76d51b0f9a4bd0ff86150d0dfa78df7c8410b7ea Mon Sep 17 00:00:00 2001 From: andy finch Date: Mon, 17 Jun 2019 21:02:08 -0400 Subject: refactor dispatch take 2 (#2533) --- core/isolate.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'core/isolate.rs') diff --git a/core/isolate.rs b/core/isolate.rs index 14e1b88aa..1ba86d727 100644 --- a/core/isolate.rs +++ b/core/isolate.rs @@ -29,13 +29,19 @@ use std::sync::{Arc, Mutex, Once, ONCE_INIT}; pub type Buf = Box<[u8]>; -pub type OpAsyncFuture = Box + Send>; +pub type OpAsyncFuture = Box + Send>; -pub enum Op { +pub enum Op { Sync(Buf), - Async(OpAsyncFuture), + Async(OpAsyncFuture), } +pub type CoreError = (); + +type CoreOpAsyncFuture = OpAsyncFuture; + +pub type CoreOp = Op; + /// Stores a script used to initalize a Isolate pub struct Script<'a> { pub source: &'a str, @@ -68,7 +74,9 @@ pub enum StartupData<'a> { None, } -type DispatchFn = Fn(&[u8], Option) -> Op; +pub type OpResult = Result, E>; + +type CoreDispatchFn = Fn(&[u8], Option) -> CoreOp; pub type DynImportFuture = Box + Send>; type DynImportFn = Fn(&str, &str) -> DynImportFuture; @@ -104,11 +112,11 @@ impl Future for DynImport { pub struct Isolate { libdeno_isolate: *const libdeno::isolate, shared_libdeno_isolate: Arc>>, - dispatch: Option>, + dispatch: Option>, dyn_import: Option>, needs_init: bool, shared: SharedQueue, - pending_ops: FuturesUnordered, + pending_ops: FuturesUnordered, pending_dyn_imports: FuturesUnordered, have_unpolled_ops: bool, startup_script: Option, @@ -184,7 +192,7 @@ impl Isolate { /// corresponds to the second argument of Deno.core.dispatch(). pub fn set_dispatch(&mut self, f: F) where - F: Fn(&[u8], Option) -> Op + Send + Sync + 'static, + F: Fn(&[u8], Option) -> CoreOp + Send + Sync + 'static, { self.dispatch = Some(Arc::new(f)); } @@ -664,7 +672,7 @@ pub mod tests { let dispatch_count_ = dispatch_count.clone(); let mut isolate = Isolate::new(StartupData::None, false); - isolate.set_dispatch(move |control, _| -> Op { + isolate.set_dispatch(move |control, _| -> CoreOp { dispatch_count_.fetch_add(1, Ordering::Relaxed); match mode { Mode::AsyncImmediate => { -- cgit v1.2.3