pub mod icrc21;
use crate::{ids::EndpointCall, perf};
use std::future::Future;
#[allow(clippy::missing_const_for_fn)]
fn ensure_memory_bootstrap() {
#[cfg(target_arch = "wasm32")]
{
if let Err(err) = crate::ops::runtime::memory::MemoryRegistryOps::ensure_bootstrap() {
panic!("runtime memory bootstrap failed before endpoint dispatch: {err}");
}
}
}
pub fn dispatch_query<R>(call: EndpointCall, f: impl FnOnce() -> R) -> R {
ensure_memory_bootstrap();
perf::enter_endpoint();
let res = f();
perf::exit_endpoint(call);
res
}
pub async fn dispatch_query_async<R, F>(call: EndpointCall, f: impl FnOnce() -> F) -> R
where
F: Future<Output = R>,
{
ensure_memory_bootstrap();
perf::enter_endpoint();
let res = f().await;
perf::exit_endpoint(call);
res
}
pub fn dispatch_update<R>(call: EndpointCall, f: impl FnOnce() -> R) -> R {
ensure_memory_bootstrap();
perf::enter_endpoint();
let res = f();
perf::exit_endpoint(call);
res
}
pub async fn dispatch_update_async<R, F>(call: EndpointCall, f: impl FnOnce() -> F) -> R
where
F: Future<Output = R>,
{
ensure_memory_bootstrap();
perf::enter_endpoint();
let res = f().await;
perf::exit_endpoint(call);
res
}