Skip to content

Commit

Permalink
Added logs to BastionContext.
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v2d0g committed Nov 13, 2019
1 parent 651a068 commit 9bd838a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bastion/src/context.rs
Expand Up @@ -103,6 +103,7 @@ impl BastionContext {
supervisor: Option<SupervisorRef>,
state: Qutex<ContextState>,
) -> Self {
debug!("BastionContext({}): Creating.", id);
BastionContext {
id,
child,
Expand Down Expand Up @@ -275,10 +276,17 @@ impl BastionContext {
/// [`recv`]: #method.recv
/// [`Msg`]: children/struct.Msg.html
pub async fn try_recv(&self) -> Option<Msg> {
debug!("BastionContext({}): Trying to receive message.", self.id);
// TODO: Err(Error)
let mut state = self.state.clone().lock_async().await.ok()?;

state.msgs.pop_front()
if let Some(msg) = state.msgs.pop_front() {
trace!("BastionContext({}): Received message: {:?}", msg);
Some(msg)
} else {
trace!("BastionContext({}): Received no message.");
None
}
}

/// Retrieves asynchronously a message received by the element
Expand Down Expand Up @@ -319,11 +327,13 @@ impl BastionContext {
/// [`try_recv`]: #method.try_recv
/// [`Msg`]: children/struct.Msg.html
pub async fn recv(&self) -> Result<Msg, ()> {
debug!("BastionContext({}): Waiting to receive message.", self.id);
loop {
// TODO: Err(Error)
let mut state = self.state.clone().lock_async().await.unwrap();

if let Some(msg) = state.msgs.pop_front() {
trace!("BastionContext({}): Received message: {:?}", msg);
return Ok(msg);
}

Expand Down

0 comments on commit 9bd838a

Please sign in to comment.