Expand description
Powerful for avoiding N+1 queries with async/await, based on the DataLoader pattern.
data_loader batches loads which occur during a single “poll”, without requiring an artificial delay.
Design inspired by https://github.com/exAspArk/batch-loader and https://github.com/graphql/dataloader
§Usage
use async_dataloader::{def_batch_loader, batched};
def_batch_loader! {
pub async fn loader(inputs: u64) -> String {
inputs.map(|input| {
input.to_string()
})
}
}
batched(async {
assert_eq!(*loader(1).await, "1".to_owned());
}).await
Macros§
- def_
batch_ loader - Define a batch loader
Structs§
- Batch
Context - Context provided when executing within a batched() future.
- Batched
- A Future which provides a BatchContext to its child while executing
Enums§
- Batch
Load - Future returned by a batch loader
Functions§
- batched
- Allows using batch loaders from within the passed future.
- delay_
loading_ batches - Provides a guard which prevents loading new batches until dropped.
- with_
batch_ ctx - Retrieves the batch context from thread local storage