dataloader/
lib.rs

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