atomr_core/pattern/ask.rs
1//! Re-export of the `ask` pattern.
2//!
3//! The primary API lives on [`crate::actor::ActorRef::ask_with`]; this free
4//! function is a convenience wrapper so users can write
5//! `ask(&target, |reply| Msg::Query(reply), Duration::from_secs(1)).await`.
6
7use std::time::Duration;
8
9use tokio::sync::oneshot;
10
11use crate::actor::{ActorRef, AskError};
12
13pub async fn ask<M: Send + 'static, R: Send + 'static, F>(
14 target: &ActorRef<M>,
15 build: F,
16 timeout: Duration,
17) -> Result<R, AskError>
18where
19 F: FnOnce(oneshot::Sender<R>) -> M,
20{
21 target.ask_with(build, timeout).await
22}