Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncWrite support #15

Open
Alexei-Kornienko opened this issue Jun 1, 2021 · 4 comments
Open

AsyncWrite support #15

Alexei-Kornienko opened this issue Jun 1, 2021 · 4 comments

Comments

@Alexei-Kornienko
Copy link

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

@PSeitz
Copy link
Owner

PSeitz commented Jun 6, 2021

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.

@Alexei-Kornienko
Copy link
Author

One solution that I could propose is:

  1. Refactor implementation to always work with AsyncWrite trait
  2. 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

@arthurprs
Copy link
Contributor

arthurprs commented Jun 9, 2021

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.

@PSeitz
Copy link
Owner

PSeitz commented Jan 24, 2023

A good idea may be to add lz4_flex support to https://github.com/Nemo157/async-compression

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants