Skip to content

Commit

Permalink
Add explicit functions for retrieving request message
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Nov 29, 2024
1 parent 74c1085 commit 8eb3af4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ector/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,28 @@ impl<M, R> Request<M, R> {
}
}

/// Process the message using a closure.
///
/// The return value of the closure is used as the response.
pub async fn process<F: FnOnce(M) -> R>(mut self, f: F) {
let reply = f(self.message.take().unwrap());
self.reply_to.send(reply).await;
}

/// Reply to the request using the provided value.
pub async fn reply(self, value: R) {
self.reply_to.send(value).await
}

/// Get a reference to the underlying message
pub fn get(&self) -> &M {
self.message.as_ref().unwrap()
}

/// Get a mutable reference to the underlying message
pub fn get_mut(&mut self) -> &mut M {
self.message.as_mut().unwrap()
}
}

impl<M, R> AsRef<M> for Request<M, R> {
Expand Down

0 comments on commit 8eb3af4

Please sign in to comment.