benjamin_batchly

Crates.iobenjamin_batchly
lib.rsbenjamin_batchly
version0.1.2
sourcesrc
created_at2022-06-04 16:09:04.361992
updated_at2024-06-28 08:18:58.595063
descriptionLow latency batching tool. Bundle lots of single concurrent operations into sequential batches of work.
homepage
repositoryhttps://github.com/alexheretic/benjamin-batchly
max_upload_size
id599763
size34,206
Alex Butler (alexheretic)

documentation

README

benjamin_batchly crates.io Documentation

Low latency batching tool. Bundle lots of single concurrent operations into sequential batches of work.

use benjamin_batchly::{BatchMutex, BatchResult};

let batcher = BatchMutex::default();

// BatchMutex synchronizes so only one `Work` happens at a time (for a given batch_key).
// All concurrent submissions made while an existing `Work` is being processed will
// await completion and form the next `Work` batch.
match batcher.submit(batch_key, item).await {
    BatchResult::Work(mut batch) => {
        db_bulk_insert(&batch.items).await?;
        batch.notify_all_done();
        Ok(())
    }
    BatchResult::Done(_) => Ok(()),
    BatchResult::Failed => Err("failed"),
}
Commit count: 15

cargo fmt