use async_channel::{Send, Sender};
use std::time::Instant;
#[cfg(doc)]
use super::Dispatcher;
#[derive(Clone, Default, Debug)]
pub struct Caller<T> {
pub(crate) inner: Option<Sender<T>>,
}
macro_rules! caller_impl {
($($name:ident: $p:ident),*) => {
impl<$($p),*> Caller<(Instant, $($p),*)> {
pub fn call(&self, $($name: $p),*) -> Send<(Instant, $($p),*)> {
self.call_later(Instant::now(), $($name),*)
}
pub fn call_later(&self, when: Instant, $($name: $p),*) -> Send<(Instant, $($p),*)> {
match &self.inner {
Some(inner) => inner.send((when, $($name),*)),
None => panic!("Uninitialized Caller!"),
}
}
}
}
}
caller_impl! {}
caller_impl! {a: P1}
caller_impl! {a: P1, b: P2}
caller_impl! {a: P1, b: P2, c: P3}
caller_impl! {a: P1, b: P2, c: P3, d: P4}
caller_impl! {a: P1, b: P2, c: P3, d: P4, e: P5}
caller_impl! {a: P1, b: P2, c: P3, d: P4, e: P5, f: P6}
caller_impl! {a: P1, b: P2, c: P3, d: P4, e: P5, f: P6, g: P7}