1#![allow(async_fn_in_trait)]
2
3pub mod async_cached;
4mod batch_fn;
5pub mod cached;
6pub mod non_cached;
7mod runtime;
8
9pub use batch_fn::BatchFn;
10
11use std::{future::Future, pin::Pin};
12
13/// A trait alias. Read as "a function which returns a pinned box containing a future"
14pub trait WaitForWorkFn:
15 Fn() -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync + 'static
16{
17}
18
19impl<T> WaitForWorkFn for T where
20 T: Fn() -> Pin<Box<dyn Future<Output = ()> + Send + Sync>> + Send + Sync + 'static
21{
22}
23
24pub(crate) fn yield_fn(count: usize) -> impl WaitForWorkFn {
25 move || {
26 Box::pin(async move {
27 // yield for other load to append request
28 for _ in 0..count {
29 runtime::yield_now().await;
30 }
31 })
32 }
33}