Skip to content

Latest commit

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

buffer

Build statusDocumentation

A stream adapter that buffers elements to improve performance when downstream tends to be busy (eg. db compactions). In comparison to buffered it works not only with Futures but any element type as there is no async.

Usage

use buffer::StreamBufferExt;use futures::stream;use futures::StreamExt;asyncfnslow_cpu_heavy_operation(x:i32) -> i32{// Simulate a CPU-heavy operation with a delaysleep(Duration::from_millis(500)).await;
x
}asyncfnmock_db_insert(x:i32){// Simulate a database insert operation that can become slow during IO bounded compactionssleep(Duration::from_millis(100)).await;}let collected:Vec<i32> = stream::iter(0..100_000).map(|x| slow_cpu_heavy_operation(x)).buffer(1000).map(|x| mock_db_insert(x)).collect().await;

About

A stream adapter that buffers elements, comes handy in case of unstable downstream processing speed

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages