Skip to content

Commit 6b564fc

Browse files
committed
Use sync functions instead of async in state_machine examples
Signed-off-by: Denis Varlakov <denis@dfns.co>
1 parent 69e7526 commit 6b564fc

File tree

1 file changed

+10
-14
lines changed
  • round-based/src/state_machine

1 file changed

+10
-14
lines changed

round-based/src/state_machine/mod.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
//!
88
//! ## Example
99
//! ```rust,no_run
10-
//! # #[tokio::main(flavor = "current_thread")]
11-
//! # async fn main() -> anyhow::Result<()> {
10+
//! # fn main() -> anyhow::Result<()> {
1211
//! use round_based::{Mpc, PartyIndex};
1312
//! use anyhow::{Result, Error, Context as _};
1413
//!
@@ -33,26 +32,23 @@
3332
//! |party| protocol_of_random_generation(party, 0, 3)
3433
//! );
3534
//!
36-
//! // Note: this is just an example. If you have stream/sink, you don't probably need to
37-
//! // use the sync API
38-
//! use futures::{Sink, Stream, SinkExt, StreamExt};
39-
//! async fn connect() -> Result<(
40-
//! impl Stream<Item = anyhow::Result<round_based::Incoming<Msg>>>,
41-
//! impl Sink<round_based::Outgoing<Msg>, Error = Error>
42-
//! )> {
43-
//! // ...
44-
//! # Ok((futures_util::stream::pending(), futures_util::sink::drain().sink_map_err(|err| match err {})))
35+
//! fn send(msg: round_based::Outgoing<Msg>) -> Result<()> {
36+
//! // sends outgoing message...
37+
//! # unimplemented!()
38+
//! }
39+
//! fn recv() -> Result<round_based::Incoming<Msg>> {
40+
//! // receives incoming message...
41+
//! # unimplemented!()
4542
//! }
46-
//! let (mut incomings, mut outgoings) = connect().await?;
4743
//!
4844
//! use round_based::state_machine::{StateMachine as _, ProceedResult};
4945
//! let output = loop {
5046
//! match state.proceed() {
5147
//! ProceedResult::SendMsg(msg) => {
52-
//! outgoings.send(msg).await?
48+
//! send(msg)?
5349
//! }
5450
//! ProceedResult::NeedsOneMoreMessage => {
55-
//! let msg = incomings.next().await.context("unexpected eof")??;
51+
//! let msg = recv()?;
5652
//! state.received_msg(msg)
5753
//! .map_err(|_| anyhow::format_err!("state machine rejected received message"))?;
5854
//! }

0 commit comments

Comments
 (0)