4 ms·
Show HN: Rust macro utility for batching expensive async operations
- 44za12 1y agoLike a sempahore?
- 0x457 1y agoSemaphore limits concurrency, this one automatically groups (batches) input.
- bombela 1y agoNeed to explain in the readme what it does, and what for. Why would I need such an abstraction? What is the cost? Why is that any better than calling the function with a single argument in the first place? I assume here it is maintaining a vector of futures and and a sibling vector of input values. And when this vector reaches the window size or something like that, it calls the original function with must returns a vector of results, which are then used to resolve the futures.
- hackermondev 1y agoThanks for the feedback, I've updated the README!
- bombela 1y agoVery nice! It's now beautifully clear what your project does and what it solves.
- catlifeonmars 1y agoAre window sizes dynamic, or do they need to be specified at build time?
- hackermondev 1y agoNeed to be specified at build time, but you can set a dynamic window length based on the current buffer length. https://github.com/hackermondev/batched?tab=readme-ov-file#batched-1 https://github.com/hackermondev/batched?tab=readme-ov-file#b...
- catlifeonmars 1y agoAh gotcha. So one use case that immediately comes to mind with batching is retries with batch bisection. While you wouldn’t need it to be arbitrarily dynamic, it would be useful to support some sort of retry aware divide-by-two mechanism
- luckystarr 1y agoThe API is great. Will definitely try it out. I have a use case already. How difficult would it be to extend this to support timed flushes? Like, every 200ms or so, regardless the fill of the buffer?
- hackermondev 1y agoThat's what the `window` option does (https://github.com/hackermondev/batched?tab=readme-ov-file#batched-1 https://github.com/hackermondev/batched?tab=readme-ov-file#b...). After the first item is added to the buffer, it waits for the maximum window time, then calls the inner function with the buffer fill.