macro_rules! impl_futures {
($f:ident, $r:ty, |$fut:ident, $cx:ident| => { $p:expr }) => {
impl_futures!($f, $r, ($fut, $cx), $p, );
};
($f:ident, $g: tt, $r:ty, |$fut:ident, $cx:ident| => { $p:expr }) => {
impl_futures!($f, $r, ($fut, $cx), $p, $g);
};
($f:ident, $r:ty, ($fut:ident, $cx:ident), $p:expr, $($g:tt)?) => {
impl $( <$g: Decode> )? FusedFuture for $f $( < $g > )? {
fn is_terminated(&self) -> bool {
!signals().waits_for(self.waiting_reply_to)
}
}
impl $( <$g: Decode> )? Future for $f $( < $g > )? {
type Output = Result<$r>;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let $fut = &mut self;
let $cx = cx;
$p
}
}
impl $( <$g: Decode> )? $f $( < $g > )? {
pub fn up_to(self, duration: Option<u32>) -> Result<Self> {
async_runtime::locks().lock(
crate::msg::id(),
self.waiting_reply_to,
Lock::up_to(duration.unwrap_or(Config::wait_up_to()))?,
);
Ok(self)
}
pub fn exactly(self, duration: Option<u32>) -> Result<Self> {
async_runtime::locks().lock(
crate::msg::id(),
self.waiting_reply_to,
Lock::exactly(duration.unwrap_or(Config::wait_for()))?,
);
Ok(self)
}
#[cfg(not(feature = "ethexe"))]
pub fn handle_reply<F: FnOnce() + 'static>(self, f: F) -> Result<Self> {
if self.reply_deposit == 0 {
return Err(Error::Gstd(crate::errors::UsageError::ZeroReplyDeposit));
}
async_runtime::reply_hooks().register(self.waiting_reply_to.clone(), f);
Ok(self)
}
}
};
}