mirror of
https://github.com/denoland/deno.git
synced 2025-02-08 07:16:56 -05:00
cleanup(core): simplify op_async(), drop need for try_dispatch_op() (#10240)
This commit is contained in:
parent
9b5d8a2f2c
commit
5b31d0f846
1 changed files with 11 additions and 24 deletions
|
@ -4,7 +4,6 @@ use crate::error::AnyError;
|
||||||
use crate::serialize_op_result;
|
use crate::serialize_op_result;
|
||||||
use crate::Op;
|
use crate::Op;
|
||||||
use crate::OpFn;
|
use crate::OpFn;
|
||||||
use crate::OpPayload;
|
|
||||||
use crate::OpState;
|
use crate::OpState;
|
||||||
use crate::ZeroCopyBuf;
|
use crate::ZeroCopyBuf;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
@ -81,33 +80,21 @@ where
|
||||||
R: Future<Output = Result<RV, AnyError>> + 'static,
|
R: Future<Output = Result<RV, AnyError>> + 'static,
|
||||||
RV: Serialize + 'static,
|
RV: Serialize + 'static,
|
||||||
{
|
{
|
||||||
let try_dispatch_op = move |state: Rc<RefCell<OpState>>,
|
Box::new(move |state, payload, buf| -> Op {
|
||||||
p: OpPayload,
|
let pid = payload.promise_id;
|
||||||
buf: Option<ZeroCopyBuf>|
|
// Deserialize args, sync error on failure
|
||||||
-> Result<Op, AnyError> {
|
let args = match payload.deserialize() {
|
||||||
let pid = p.promise_id;
|
Ok(args) => args,
|
||||||
// Parse args
|
Err(err) => {
|
||||||
let args = p.deserialize()?;
|
return Op::Sync(serialize_op_result(Err::<(), AnyError>(err), state))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
use crate::futures::FutureExt;
|
use crate::futures::FutureExt;
|
||||||
let fut = op_fn(state.clone(), args, buf)
|
let fut = op_fn(state.clone(), args, buf)
|
||||||
.map(move |result| (pid, serialize_op_result(result, state)));
|
.map(move |result| (pid, serialize_op_result(result, state)));
|
||||||
Ok(Op::Async(Box::pin(fut)))
|
Op::Async(Box::pin(fut))
|
||||||
};
|
})
|
||||||
|
|
||||||
Box::new(
|
|
||||||
move |state: Rc<RefCell<OpState>>,
|
|
||||||
p: OpPayload,
|
|
||||||
b: Option<ZeroCopyBuf>|
|
|
||||||
-> Op {
|
|
||||||
match try_dispatch_op(state.clone(), p, b) {
|
|
||||||
Ok(op) => op,
|
|
||||||
Err(err) => {
|
|
||||||
Op::Sync(serialize_op_result(Err::<(), AnyError>(err), state))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue