#[wait_for_reply]
Expand description
Extends async methods for_reply
and for_reply_as
for sending
methods.
§Usage
ⓘ
use gcore::errors::Result;
#[wait_for_reply]
pub fn send_bytes<T: AsRef<[u8]>>(program: ActorId, payload: T, value: u128) -> Result<MessageId> {
gcore::msg::send(program.into(), payload.as_ref(), value)
}
outputs:
ⓘ
/// Same as [`send_bytes`](self::send_bytes), but the program
/// will interrupt until the reply is received.
///
/// Argument `reply_deposit: u64` used to provide gas for
/// future reply handling (skipped if zero).
///
/// # See also
///
/// - [`send_bytes_for_reply_as`](self::send_bytes_for_reply_as)
pub fn send_bytes_for_reply<T: AsRef<[u8]>>(
program: ActorId,
payload: T,
value: u128,
reply_deposit: u64
) -> Result<crate::msg::MessageFuture> {
// Function call.
let waiting_reply_to = send_bytes(program, payload, value)?;
// Depositing gas for future reply handling if not zero.
if reply_deposit != 0 {
crate::exec::reply_deposit(waiting_reply_to, reply_deposit)?;
}
// Registering signal.
crate::async_runtime::signals().register_signal(waiting_reply_to);
Ok(crate::msg::MessageFuture { waiting_reply_to })
}
/// Same as [`send_bytes`](self::send_bytes), but the program
/// will interrupt until the reply is received.
///
/// Argument `reply_deposit: u64` used to provide gas for
/// future reply handling (skipped if zero).
///
/// The output should be decodable via SCALE codec.
///
/// # See also
///
/// - [`send_bytes_for_reply`](self::send_bytes_for_reply)
/// - <https://docs.substrate.io/reference/scale-codec>
pub fn send_bytes_for_reply_as<T: AsRef<[u8]>, D: crate::codec::Decode>(
program: ActorId,
payload: T,
value: u128,
reply_deposit: u64,
) -> Result<crate::msg::CodecMessageFuture<D>> {
// Function call.
let waiting_reply_to = send_bytes(program, payload, value)?;
// Depositing gas for future reply handling if not zero.
if reply_deposit != 0 {
crate::exec::reply_deposit(waiting_reply_to, reply_deposit)?;
}
// Registering signal.
crate::async_runtime::signals().register_signal(waiting_reply_to);
Ok(crate::msg::CodecMessageFuture::<D> {
waiting_reply_to,
_marker: Default::default(),
})
}