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

AsyncBufReader / AsyncBufWriter #1519

Closed
yoshuawuyts opened this issue Apr 12, 2019 · 3 comments · Fixed by #1608
Closed

AsyncBufReader / AsyncBufWriter #1519

yoshuawuyts opened this issue Apr 12, 2019 · 3 comments · Fixed by #1608

Comments

@yoshuawuyts
Copy link
Member

Similar to #1512, we've been missing an async equivalent of std's io::BufReader and io::BufWriter. This would be useful to reduce the amount of system calls, and speed up throughput.

@Nemo157
Copy link
Member

Nemo157 commented Apr 15, 2019

I've experimented with this in embrio with trait AsyncBufRead, an async struct BufReader and an implementation of async fn read_until (the latter can definitely be simplified by providing async fn fill_buf() on top of fn poll_fill_buf() and actually using async fn syntax). These have definitely worked well, and it should be straightforward to port std-like variants into futures (these were a little different than the ones provided in std since embrio is alloc-less).

@taiki-e
Copy link
Member

taiki-e commented Apr 25, 2019

std::io::BufWriter implements Drop, and it is convenient. Do you think that async BufWriter can also implement it? (functions that call flush_buf (flushes the internal buffer) internally need to receive a context. into_inner also has the same problem.)

@Nemo157
Copy link
Member

Nemo157 commented Apr 25, 2019

IMO anyone using an async writer should be calling close on it to ensure it's fully flushed and closed, dropping a writer without closing it is allowed to just abandon any outstanding writes (which is something that probably needs documenting on AsyncWrite). Having std::io::Write implementations set the precedent that dropping will flush outstanding writes and swallow errors is quite unfortunate though.

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

Successfully merging a pull request may close this issue.

3 participants