|
7 | 7 | //!
|
8 | 8 | //! ## Example
|
9 | 9 | //! ```rust,no_run
|
10 |
| -//! # #[tokio::main(flavor = "current_thread")] |
11 |
| -//! # async fn main() -> anyhow::Result<()> { |
| 10 | +//! # fn main() -> anyhow::Result<()> { |
12 | 11 | //! use round_based::{Mpc, PartyIndex};
|
13 | 12 | //! use anyhow::{Result, Error, Context as _};
|
14 | 13 | //!
|
|
33 | 32 | //! |party| protocol_of_random_generation(party, 0, 3)
|
34 | 33 | //! );
|
35 | 34 | //!
|
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!() |
45 | 42 | //! }
|
46 |
| -//! let (mut incomings, mut outgoings) = connect().await?; |
47 | 43 | //!
|
48 | 44 | //! use round_based::state_machine::{StateMachine as _, ProceedResult};
|
49 | 45 | //! let output = loop {
|
50 | 46 | //! match state.proceed() {
|
51 | 47 | //! ProceedResult::SendMsg(msg) => {
|
52 |
| -//! outgoings.send(msg).await? |
| 48 | +//! send(msg)? |
53 | 49 | //! }
|
54 | 50 | //! ProceedResult::NeedsOneMoreMessage => {
|
55 |
| -//! let msg = incomings.next().await.context("unexpected eof")??; |
| 51 | +//! let msg = recv()?; |
56 | 52 | //! state.received_msg(msg)
|
57 | 53 | //! .map_err(|_| anyhow::format_err!("state machine rejected received message"))?;
|
58 | 54 | //! }
|
|
0 commit comments