Skip to content

Commit

Permalink
Use sync functions instead of async in state_machine examples
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Varlakov <denis@dfns.co>
  • Loading branch information
survived committed Dec 3, 2024
1 parent 69e7526 commit 6b564fc
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions round-based/src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
//!
//! ## Example
//! ```rust,no_run
//! # #[tokio::main(flavor = "current_thread")]
//! # async fn main() -> anyhow::Result<()> {
//! # fn main() -> anyhow::Result<()> {
//! use round_based::{Mpc, PartyIndex};
//! use anyhow::{Result, Error, Context as _};
//!
Expand All @@ -33,26 +32,23 @@
//! |party| protocol_of_random_generation(party, 0, 3)
//! );
//!
//! // Note: this is just an example. If you have stream/sink, you don't probably need to
//! // use the sync API
//! use futures::{Sink, Stream, SinkExt, StreamExt};
//! async fn connect() -> Result<(
//! impl Stream<Item = anyhow::Result<round_based::Incoming<Msg>>>,
//! impl Sink<round_based::Outgoing<Msg>, Error = Error>
//! )> {
//! // ...
//! # Ok((futures_util::stream::pending(), futures_util::sink::drain().sink_map_err(|err| match err {})))
//! fn send(msg: round_based::Outgoing<Msg>) -> Result<()> {
//! // sends outgoing message...
//! # unimplemented!()
//! }
//! fn recv() -> Result<round_based::Incoming<Msg>> {
//! // receives incoming message...
//! # unimplemented!()
//! }
//! let (mut incomings, mut outgoings) = connect().await?;
//!
//! use round_based::state_machine::{StateMachine as _, ProceedResult};
//! let output = loop {
//! match state.proceed() {
//! ProceedResult::SendMsg(msg) => {
//! outgoings.send(msg).await?
//! send(msg)?
//! }
//! ProceedResult::NeedsOneMoreMessage => {
//! let msg = incomings.next().await.context("unexpected eof")??;
//! let msg = recv()?;
//! state.received_msg(msg)
//! .map_err(|_| anyhow::format_err!("state machine rejected received message"))?;
//! }
Expand Down

0 comments on commit 6b564fc

Please sign in to comment.