Show HN: Rust macro utility for batching expensive async operations

https://news.ycombinator.com/rss Hits: 5
Summary

batched Rust macro utility for batching expensive async operations. Installation cargo add batched Or add this to your Cargo.toml : [ dependencies ] batched = " 0.2.7 " limit : Maximum amount of items that can be grouped and processed in a single batch. : Maximum amount of items that can be grouped and processed in a single batch. concurrent : Maximum amount of concurrent batched tasks running (default: Infinity ) : Maximum amount of concurrent batched tasks running (default: ) window : Minimum amount of time (in milliseconds) the background thread waits before processing a batch. : Minimum amount of time (in milliseconds) the background thread waits before processing a batch. window[x]: Minimum amount of time (in milliseconds) the background thread waits before processing a batch when latest buffer size is <= x The target function must have a single argument, a vector of items ( Vec<T> ). The return value of the batched function is propagated (cloned) to all async calls of the batch, unless the batched function returns a Vec<T> , in which case the return value for each call is pulled from the iterator in the same order of the input. If the return value is not an iterator, The target function return type must implement Clone to propagate the result. Use batched::error::SharedError to wrap your error types (if they don't implement Clone). Prerequisites Built for async environments (tokio), will not work without a tokio async runtime Target function must have async Not supported inside structs: struct A ; impl A { # [ batched ( window = 1000 , limit = 100 ) ] fn operation ( ) { .. . } } Tracing This feature automatically adds tracing spans to call functions for batched requests ( x , x_multiple ). This feature adds support for linking spans from callers to the inner batched call when using OpenTelemetry. Depending on whether your OpenTelemetry client supports it, you should be able to see the linked span to the batched call. Examples Simple add batch # [ batched ( win...

First seen: 2025-08-17 14:35

Last seen: 2025-08-17 18:36