You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Update dependencies and Rust version to 2024
* Update GitHub Actions workflow to use latest action versions and simplify steps
* Bump version
* update email
* Brush up docs
An adaptor that chunks up completed futures in a stream and flushes them after a timeout or when the buffer is full.
8
-
It is based on the `Chunks` adaptor of [futures-util](https://github.com/rust-lang-nursery/futures-rs/blob/4613193023dd4071bbd32b666e3b85efede3a725/futures-util/src/stream/chunks.rs), to which we added a timeout.
7
+
A stream adaptor that chunks up items with timeout support. Items are flushed when:
8
+
- The buffer reaches capacity **or**
9
+
- A timeout occurs
9
10
10
-
(The project was initially called `tokio-batch`, but was renamed as it has no dependency on Tokio anymore.)
11
+
Based on the `Chunks` adaptor from [futures-util](https://github.com/rust-lang/futures-rs), with added timeout functionality.
12
+
13
+
> **Note:** Originally called `tokio-batch`, but renamed since it has no dependency on Tokio.
11
14
12
15
## Usage
13
16
14
-
Either as a standalone stream operator or directly as a combinator:
17
+
Add to your `Cargo.toml`:
18
+
19
+
```toml
20
+
[dependencies]
21
+
futures-batch = "0.7"
22
+
```
23
+
24
+
Use as a stream combinator:
15
25
16
26
```rust
17
27
usestd::time::Duration;
@@ -21,21 +31,38 @@ use futures_batch::ChunksTimeoutStreamExt;
The above code iterates over a stream and creates chunks of size 5 with a timeout of 10 seconds.
32
-
_Note:_ This is using the [`futures 0.3`](https://crates.io/crates/futures) crate.
42
+
This creates chunks of up to 5 items with a 10-second timeout.
43
+
44
+
## Features
45
+
46
+
### `sink` (optional)
47
+
48
+
Enable `Sink` support for bidirectional streams:
49
+
50
+
```toml
51
+
[dependencies]
52
+
futures-batch = { version = "0.7", features = ["sink"] }
53
+
```
54
+
55
+
When enabled, `ChunksTimeout` implements `Sink` and forwards sink operations to the underlying stream.
33
56
34
57
## Performance
35
58
36
-
`futures-batch` imposes very low overhead on your application. For example, it [is even used to batch syscalls](https://github.com/mre/futures-batch/issues/4).
37
-
Under the hood, we are using [`futures-timer`](https://github.com/async-rs/futures-timer), which allows for a microsecond timer resolution.
38
-
If you find a use-case which is not covered, don't be reluctant to open an issue.
59
+
`futures-batch` has minimal overhead and is suitable for high-performance applications:
60
+
61
+
- Used for [batching syscalls](https://github.com/mre/futures-batch/issues/4) in production
62
+
- Built on [`futures-timer`](https://github.com/async-rs/futures-timer) with microsecond resolution
63
+
- Zero allocations for chunk creation (reuses capacity)
64
+
65
+
Benchmarks show consistent ~20ns per operation across different batch sizes.
0 commit comments