lz4_flex
lz4_flex copied to clipboard
AsyncWrite support
Would be good to add impl of FrameEncoder/FrameDecoder where W: AsyncWrite (futures::io::AsyncWrite), R: AsyncRead
This would enable user the possibility to use compression in async data streams
Thanks for the issue, yeah I also thought about that. It would be nice to have, but I'm not sure how good it can be managed to have both in terms of code duplication.
One solution that I could propose is:
- Refactor implementation to always work with AsyncWrite trait
- Add a thin Wrapper that would take any type that implement Write and impl AsyncWrite for it without returning Poll::Pending
In result Async version would be used as is. Sync version could internally use block_on (https://docs.rs/futures/0.3.15/futures/executor/fn.block_on.html) to convert sync call to async call
Pros:
- only 1 impl of the algorithm without copy/paste
- for sync version compiler should be able to optimize out all await keywords and make it zero cost (need to benchmark)
Cons:
- hard dependency on futures crate
- slightly more complicated code using async/await syntax
One significant problem right now is that the ecosystem is split regarding AsyncRead/Write. Every runtime has an its own (tokio, ..) set of traits and the futures crates have another one.
A good idea may be to add lz4_flex support to https://github.com/Nemo157/async-compression