cleanup(core): simplify op_async(), drop need for try_dispatch_op()
@@ -4,7 +4,6 @@ use crate::error::AnyError;
use crate::serialize_op_result;
use crate::Op;
use crate::OpFn;
-use crate::OpPayload;
use crate::OpState;
use crate::ZeroCopyBuf;
use serde::de::DeserializeOwned;
@@ -81,33 +80,21 @@ where
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: Serialize + 'static,
{
- let try_dispatch_op = move |state: Rc<RefCell<OpState>>,
- p: OpPayload,
- buf: Option<ZeroCopyBuf>|
- -> Result<Op, AnyError> {
- let pid = p.promise_id;
- // Parse args
- let args = p.deserialize()?;
+ Box::new(move |state, payload, buf| -> Op {
+ let pid = payload.promise_id;
+ // Deserialize args, sync error on failure
+ let args = match payload.deserialize() {
+ Ok(args) => args,
+ Err(err) => {
+ return Op::Sync(serialize_op_result(Err::<(), AnyError>(err), state))
+ }
+ };
use crate::futures::FutureExt;
let fut = op_fn(state.clone(), args, buf)
.map(move |result| (pid, serialize_op_result(result, state)));
- Ok(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))
- }
- }
- },
- )
+ Op::Async(Box::pin(fut))
+ })
}
#[cfg(test)]
