canic_core/
dispatch.rs

1use crate::perf_scope;
2use std::future::Future;
3
4/// Dispatch a synchronous query endpoint.
5pub fn dispatch_query<R>(label: &'static str, f: impl FnOnce() -> R) -> R {
6    perf_scope!("{label}");
7    f()
8}
9
10/// Dispatch an asynchronous query endpoint.
11pub async fn dispatch_query_async<R, F>(label: &'static str, f: impl FnOnce() -> F) -> R
12where
13    F: Future<Output = R>,
14{
15    perf_scope!("{label}");
16    f().await
17}
18
19/// Dispatch a synchronous update endpoint.
20pub fn dispatch_update<R>(label: &'static str, f: impl FnOnce() -> R) -> R {
21    perf_scope!("{label}");
22    f()
23}
24
25/// Dispatch an asynchronous update endpoint.
26pub async fn dispatch_update_async<R, F>(label: &'static str, f: impl FnOnce() -> F) -> R
27where
28    F: Future<Output = R>,
29{
30    perf_scope!("{label}");
31    f().await
32}