pub async fn try_recv(&self) -> Option<SignedMessage> {
        debug!("BastionContext({}): Trying to receive message.", self.id);
        // TODO: Err(Error)
        let mut state = self.state.clone().lock_async().await.ok()?;

        if let Some(msg) = state.msgs.pop_front() {
            trace!("BastionContext({}): Received message: {:?}", self.id, msg);
            Some(msg)
        } else {
            trace!("BastionContext({}): Received no message.", self.id);
            None
        }
    }
/// Tries to retrieve asynchronously a message received by
/// the element this `BastionContext` is linked to.
///
/// If you need to wait (always asynchronously) until at
/// least one message can be retrieved, use [`recv`] instead.
///
/// This method returns [`SignedMessage`] if a message was available, or
/// `None` otherwise.
///
/// # Example
///
/// ```rust
/// # use bastion::prelude::*;
/// #
/// # fn main() {
///     # Bastion::init();
///     #
/// Bastion::children(|children| {
///     children.with_exec(|ctx: BastionContext| {
///         async move {
///             let opt_msg: Option<SignedMessage> = ctx.try_recv().await;
///             // If a message was received by the element, `opt_msg` will
///             // be `Some(Msg)`, otherwise it will be `None`.
///
///             Ok(())
///         }
///     })
/// }).expect("Couldn't create the children group.");
///     #
///     # Bastion::start();
///     # Bastion::stop();
///     # Bastion::block_until_stopped();
/// # }
/// ```
///
/// [`recv`]: #method.recv
/// [`SignedMessage`]: ../prelude/struct.SignedMessage.html
Tries to retrieve asynchronously a message received by
the element this `BastionContext` is linked to.

If you need to wait (always asynchronously) until at
least one message can be retrieved, use [`recv`] instead.

This method returns [`SignedMessage`] if a message was available, or
`None` otherwise.
Tries to retrieve asynchronously a message received by the element this ` BastionContext ` is linked to . If you need to wait ( always asynchronously ) until at least one message can be retrieved use [ ` recv ` ] instead . This method returns [ ` SignedMessage ` ] if a message was available or ` None ` otherwise .
pub async fn try_recv(&self) -> Option<SignedMessage> {
        debug!("BastionContext({}): Trying to receive message.", self.id);
        // TODO: Err(Error)
        let mut state = self.state.clone().lock_async().await.ok()?;
        if let Some(msg) = state.msgs.pop_front() {
            trace!("BastionContext({}): Received message: {:?}", self.id, msg);
            Some(msg)
        } else {
            trace!("BastionContext({}): Received no message.", self.id);
            None
        }
    }
pub async fn try_recv ( & self ) -> Option < SignedMessage > { debug ! ( " " self id ) ; // TODO: Err(Error) let mut state = self . state . clone ( ) . lock_async ( ) . await . ok ( ) ? ; if let Some ( msg ) = state . msgs . pop_front ( ) { trace ! ( " " self id msg ) ; Some ( msg ) } else { trace ! ( " " self id ) ; None } }
Tries to retrieve asynchronously a message received by
the element this `BastionContext` is linked to.
Tries to retrieve asynchronously a message received by the element this ` BastionContext ` is linked to .
&self
&self
example
None
use bastion::prelude::*;
None
fn main() {


:children(|children| {
children.with_exec(|ctx: BastionContext| {
async move {
let opt_msg: Option = ctx.try_recv().await;
If a message was received by the element, `opt_msg` will
be `Some(Msg)`, otherwise it will be `None`.

Ok(())
}
})
}).expect("Couldn't create the children group.").

:start();
Bastion::stop();
Bastion::block_until_stopped().
: children ( |children| { children . with_exec ( |ctx : BastionContext| { async move { let opt_msg : Option = ctx . try_recv () . await ; If a message was received by the element ` opt_msg ` will be ` Some ( Msg ) ` otherwise it will be ` None ` . Ok (( )) } } ) } ) . expect ( " Couldn ' t create the children group . " ) . : start () ; Bastion :: stop () ; Bastion :: block_until_stopped () .
}


[`recv`]: #method.recv
[`SignedMessage`]: ../prelude/struct.SignedMessage.html
[ ` recv ` ] : #method . recv [ ` SignedMessage ` ] : .. / prelude / struct . SignedMessage . html