1use super::*;
2use std::future::Future;
3
4pub trait Sends<T: Message> {
6 fn send(&self, msg: T) -> impl Future<Output = Result<Output<T>, SendError<T>>> + Send + '_;
8
9 fn send_blocking(&self, msg: T) -> Result<Output<T>, SendError<T>> {
11 futures::executor::block_on(self.send(msg))
12 }
13}
14
15pub trait SendsExt<T: Message>: Sends<T> {
17 fn request(
21 &self,
22 msg: T,
23 ) -> impl Future<Output = Result<Reply<T>, RequestError<T>>> + Send + '_ {
24 let fut = self.send(msg);
25
26 async { Ok(fut.await?.receive().await?) }
27 }
28
29 fn request_blocking(&self, msg: T) -> Result<Reply<T>, RequestError<T>> {
31 Ok(self.send_blocking(msg)?.receive_blocking()?)
32 }
33}
34impl<T: Message, S: Sends<T>> SendsExt<T> for S {}