diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2020-01-22 02:01:10 +0900 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2020-01-21 12:01:10 -0500 |
commit | 9de8178c9b9bc21cc880ea81f163118408cc6c46 (patch) | |
tree | ec0e7f46868959bf5132d562f9a2258d2437176a /cli/ops/dispatch_json.rs | |
parent | ecd1d3abb0cae9c7cbc1330cbaa035a5786e94d7 (diff) |
feat: add AsyncUnref ops (#3721)
This is in order to support features like signal handlers, which
shouldn't prevent the program from exiting.
Diffstat (limited to 'cli/ops/dispatch_json.rs')
-rw-r--r-- | cli/ops/dispatch_json.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs index de1f0a752..87cfff51d 100644 --- a/cli/ops/dispatch_json.rs +++ b/cli/ops/dispatch_json.rs @@ -14,6 +14,9 @@ pub type AsyncJsonOp = pub enum JsonOp { Sync(Value), Async(AsyncJsonOp), + /// AsyncUnref is the variation of Async, which doesn't block the program + /// exiting. + AsyncUnref(AsyncJsonOp), } fn json_err(err: ErrBox) -> Value { @@ -77,6 +80,13 @@ where }); CoreOp::Async(fut2.boxed()) } + Ok(JsonOp::AsyncUnref(fut)) => { + assert!(promise_id.is_some()); + let fut2 = fut.then(move |result| { + futures::future::ok(serialize_result(promise_id, result)) + }); + CoreOp::AsyncUnref(fut2.boxed()) + } Err(sync_err) => { let buf = serialize_result(promise_id, Err(sync_err)); if is_sync { |