use crate::actor::Actor;
use crate::channel::{mpsc, oneshot};
use crate::envelope::{Envelope, IntoEnvelope};
use crate::message::Message;
#[derive(Debug)]
pub struct SendPermit<'a, A>
where
A: Actor,
{
pub(super) permit: mpsc::Permit<'a, Envelope<A>>,
}
impl<A> SendPermit<'_, A>
where
A: Actor,
{
pub fn send<M, EP>(self, msg: M) -> oneshot::Receiver<M::Result>
where
M: Message + IntoEnvelope<A, EP>,
{
let (tx, rx) = oneshot::channel();
self.permit.send(msg.pack(Some(tx)));
rx
}
pub fn do_send<M, EP>(self, msg: M)
where
M: Message + IntoEnvelope<A, EP>,
{
self.permit.send(msg.pack(None));
}
}
#[derive(Debug)]
pub struct OwnedSendPermit<A>
where
A: Actor,
{
pub(super) permit: mpsc::OwnedPermit<Envelope<A>>,
}
impl<A> OwnedSendPermit<A>
where
A: Actor,
{
pub fn send<M, EP>(self, msg: M) -> oneshot::Receiver<M::Result>
where
M: Message + IntoEnvelope<A, EP>,
{
let (tx, rx) = oneshot::channel();
self.permit.send(msg.pack(Some(tx)));
rx
}
pub fn do_send<M, EP>(self, msg: M)
where
M: Message + IntoEnvelope<A, EP>,
{
self.permit.send(msg.pack(None));
}
}