Skip to main content

reply

Function reply 

Source
pub fn reply(
    key: &(impl ToCallKey + ?Sized),
    answer: Result<impl Shaped + Debug, ToolProblem>,
) -> Result<Ack, ReplyError>
Expand description

Answers the open call key names with answer, and returns what the host did with it: Ack::Ok when the answer is recorded, Ack::AlreadyAnswered when the call was not open, with same true if its answer equals this one, and Ack::TypeError when the answer does not have the call’s type. The last two record nothing and do not stop the run.

It goes to the host whose socket FLOW_REPLY_SOCKET names; with that variable unset or empty it reaches no host. reply_at names the socket instead. While a testing::replies capture is alive, the reply is recorded there instead and nothing reaches a host.

§Errors

A key that is not a key’s text form is refused before anything is sent, and a value that is not one of the call’s result type, ReplyError::Mistyped, before the reply is sent. No FLOW_REPLY_SOCKET is ReplyError::NoSocket, a socket that fails ReplyError::Socket, and a host that answers out of turn ReplyError::Answered. A host that has no result type for the call, such as one that does not hold its run, is ReplyError::Untyped, and one that ends the connection before its ack is ReplyError::Ended.

An answer is a value or a problem:

use flow_toolkit::{CallKey, ToolProblem, reply};
let key: CallKey = "7f3a91c04be2d5e6f708192a3b4c5d6e/root#1".parse()?;
reply(&key, Ok("approved".to_owned()))?;
reply(&key, Err::<String, _>(ToolProblem::Interrupted("withdrawn".into())))?;

A hold is no answer, so it does not compile:

ⓘ
use flow_toolkit::{CallKey, Hold, reply};
let key: CallKey = "7f3a91c04be2d5e6f708192a3b4c5d6e/root#1".parse()?;
reply(&key, Err::<String, _>(Hold::new()))?;