diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2019-10-02 00:51:05 +0200 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-10-01 18:51:05 -0400 |
commit | 75eeac03f31521dff1ef7db9ff2a9cb32a97b111 (patch) | |
tree | 162e448213ab99b88f9fd39796ec90db54cd6db7 /cli/ops/dispatch_minimal.rs | |
parent | ffbf0c20ccc4e70281958f18ed117f40bdd91397 (diff) |
use Isolate::register_op in deno_cli (#3039)
Diffstat (limited to 'cli/ops/dispatch_minimal.rs')
-rw-r--r-- | cli/ops/dispatch_minimal.rs | 63 |
1 files changed, 31 insertions, 32 deletions
diff --git a/cli/ops/dispatch_minimal.rs b/cli/ops/dispatch_minimal.rs index f52893951..618a040bf 100644 --- a/cli/ops/dispatch_minimal.rs +++ b/cli/ops/dispatch_minimal.rs @@ -4,7 +4,6 @@ //! alternative to flatbuffers using a very simple list of int32s to lay out //! messages. The first i32 is used to determine if a message a flatbuffer //! message or a "minimal" message. -use crate::state::ThreadSafeState; use deno::Buf; use deno::CoreOp; use deno::ErrBox; @@ -72,40 +71,40 @@ fn test_parse_min_record() { assert_eq!(parse_min_record(&buf), None); } -pub fn dispatch( +pub fn minimal_op( d: Dispatcher, - _state: &ThreadSafeState, - control: &[u8], - zero_copy: Option<PinnedBuf>, -) -> CoreOp { - let mut record = parse_min_record(control).unwrap(); - let is_sync = record.promise_id == 0; - let rid = record.arg; - let min_op = d(rid, zero_copy); +) -> impl Fn(&[u8], Option<PinnedBuf>) -> CoreOp { + move |control: &[u8], zero_copy: Option<PinnedBuf>| { + let mut record = parse_min_record(control).unwrap(); + let is_sync = record.promise_id == 0; + let rid = record.arg; + let min_op = d(rid, zero_copy); - let fut = Box::new(min_op.then(move |result| -> Result<Buf, ()> { - match result { - Ok(r) => { - record.result = r; + // Convert to CoreOp + let fut = Box::new(min_op.then(move |result| -> Result<Buf, ()> { + match result { + Ok(r) => { + record.result = r; + } + Err(err) => { + // TODO(ry) The dispatch_minimal doesn't properly pipe errors back to + // the caller. + debug!("swallowed err {}", err); + record.result = -1; + } } - Err(err) => { - // TODO(ry) The dispatch_minimal doesn't properly pipe errors back to - // the caller. - debug!("swallowed err {}", err); - record.result = -1; - } - } - Ok(record.into()) - })); + Ok(record.into()) + })); - if is_sync { - // Warning! Possible deadlocks can occur if we try to wait for a future - // while in a future. The safe but expensive alternative is to use - // tokio_util::block_on. - // This block is only exercised for readSync and writeSync, which I think - // works since they're simple polling futures. - Op::Sync(fut.wait().unwrap()) - } else { - Op::Async(fut) + if is_sync { + // Warning! Possible deadlocks can occur if we try to wait for a future + // while in a future. The safe but expensive alternative is to use + // tokio_util::block_on. + // This block is only exercised for readSync and writeSync, which I think + // works since they're simple polling futures. + Op::Sync(fut.wait().unwrap()) + } else { + Op::Async(fut) + } } } |