Crate async_dataloader

Source
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§

BatchContext
Context provided when executing within a batched() future.
Batched
A Future which provides a BatchContext to its child while executing

Enums§

BatchLoad
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