Futures-rs: AsyncBufReader / AsyncBufWriter

Created on 13 Apr 2019  路  3Comments  路  Source: rust-lang/futures-rs

Similar to https://github.com/rust-lang-nursery/futures-rs/issues/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.

Most helpful comment

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.

All 3 comments

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).

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.)

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jimblandy picture jimblandy  路  5Comments

hh9527 picture hh9527  路  4Comments

jedisct1 picture jedisct1  路  3Comments

mqudsi picture mqudsi  路  5Comments

seanmonstar picture seanmonstar  路  4Comments