canic_core/
dispatch.rs

1use crate::perf;
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::enter_endpoint();
7    let result = f();
8    perf::exit_endpoint(label);
9    result
10}
11
12/// Dispatch an asynchronous query endpoint.
13pub async fn dispatch_query_async<R, F>(label: &'static str, f: impl FnOnce() -> F) -> R
14where
15    F: Future<Output = R>,
16{
17    perf::enter_endpoint();
18    let result = f().await;
19    perf::exit_endpoint(label);
20    result
21}
22
23/// Dispatch a synchronous update endpoint.
24pub fn dispatch_update<R>(label: &'static str, f: impl FnOnce() -> R) -> R {
25    perf::enter_endpoint();
26    let result = f();
27    perf::exit_endpoint(label);
28    result
29}
30
31/// Dispatch an asynchronous update endpoint.
32pub async fn dispatch_update_async<R, F>(label: &'static str, f: impl FnOnce() -> F) -> R
33where
34    F: Future<Output = R>,
35{
36    perf::enter_endpoint();
37    let result = f().await;
38    perf::exit_endpoint(label);
39    result
40}