[][src]Struct round_based::async_runtime::AsyncProtocol

pub struct AsyncProtocol<SM, I, O, W = BlindWatcher> { /* fields omitted */ }

Executes protocol in async environment using tokio backend

In the most simple setting, you just provide protocol initial state, stream of incoming messages, and sink for outcoming messages, and you're able to easily execute it:

fn incoming() -> impl Stream<Item=Result<Msg<M>, Error>> + FusedStream + Unpin {
    // ...
}
fn outcoming() -> impl Sink<Msg<M>, Error=Error> + Unpin {
    // ...
}
let output: State::Output = AsyncProtocol::new(State::initial(), incoming(), outcoming())
    .run().await?;
// ...

Note that in most cases it's your responsibility to provide a secure P2P channels to every party.

Implementations

impl<SM, I, O> AsyncProtocol<SM, I, O, BlindWatcher>[src]

pub fn new(state: SM, incoming: I, outcoming: O) -> Self[src]

Construct new executor from protocol initial state, channels of incoming and outcoming messages

impl<SM, I, O, W> AsyncProtocol<SM, I, O, W>[src]

pub fn set_watcher<WR>(self, watcher: WR) -> AsyncProtocol<SM, I, O, WR>[src]

Sets new protocol watcher

Protocol watcher looks after protocol execution. See list of observable events in ProtocolWatcher trait.

Default watcher: BlindWatcher that does nothing with received events. For development purposes it's convenient to pick StderrWatcher.

impl<SM, I, O, IErr, W> AsyncProtocol<SM, I, O, W> where
    SM: StateMachine,
    SM::Err: Send,
    SM: Send + 'static,
    I: Stream<Item = Result<Msg<SM::MessageBody>, IErr>> + FusedStream + Unpin,
    O: Sink<Msg<SM::MessageBody>> + Unpin,
    W: ProtocolWatcher<SM>, 
[src]

pub async fn run(
    &mut self
) -> Result<SM::Output, Error<SM::Err, IErr, O::Error>>
[src]

Executes the protocol

Returns protocol output or first occurred critical error

Auto Trait Implementations

impl<SM, I, O, W> RefUnwindSafe for AsyncProtocol<SM, I, O, W> where
    I: RefUnwindSafe,
    O: RefUnwindSafe,
    SM: RefUnwindSafe,
    W: RefUnwindSafe
[src]

impl<SM, I, O, W> Send for AsyncProtocol<SM, I, O, W> where
    I: Send,
    O: Send,
    SM: Send,
    W: Send
[src]

impl<SM, I, O, W> Sync for AsyncProtocol<SM, I, O, W> where
    I: Sync,
    O: Sync,
    SM: Sync,
    W: Sync
[src]

impl<SM, I, O, W> Unpin for AsyncProtocol<SM, I, O, W> where
    I: Unpin,
    O: Unpin,
    SM: Unpin,
    W: Unpin
[src]

impl<SM, I, O, W> UnwindSafe for AsyncProtocol<SM, I, O, W> where
    I: UnwindSafe,
    O: UnwindSafe,
    SM: UnwindSafe,
    W: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.