This commit is contained in:
Stjepan Glavina 2020-09-27 23:15:26 +02:00
parent aae2473a80
commit 3cc2c42669
1 changed files with 0 additions and 16 deletions

View File

@ -575,15 +575,11 @@ impl<T> Async<T> {
pub async fn read_with<R>(&self, op: impl FnMut(&T) -> io::Result<R>) -> io::Result<R> {
let mut op = op;
loop {
// Yield with some small probability - this improves fairness.
future::poll_fn(|cx| maybe_yield(cx)).await;
match op(self.get_ref()) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return res,
}
// Wait until the I/O handle becomes readable.
optimistic(self.readable()).await?;
}
}
@ -616,15 +612,11 @@ impl<T> Async<T> {
) -> io::Result<R> {
let mut op = op;
loop {
// Yield with some small probability - this improves fairness.
future::poll_fn(|cx| maybe_yield(cx)).await;
match op(self.get_mut()) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return res,
}
// Wait until the I/O handle becomes readable.
optimistic(self.readable()).await?;
}
}
@ -655,15 +647,11 @@ impl<T> Async<T> {
pub async fn write_with<R>(&self, op: impl FnMut(&T) -> io::Result<R>) -> io::Result<R> {
let mut op = op;
loop {
// Yield with some small probability - this improves fairness.
future::poll_fn(|cx| maybe_yield(cx)).await;
match op(self.get_ref()) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return res,
}
// Wait until the I/O handle becomes writable.
optimistic(self.writable()).await?;
}
}
@ -697,15 +685,11 @@ impl<T> Async<T> {
) -> io::Result<R> {
let mut op = op;
loop {
// Yield with some small probability - this improves fairness.
future::poll_fn(|cx| maybe_yield(cx)).await;
match op(self.get_mut()) {
Err(err) if err.kind() == io::ErrorKind::WouldBlock => {}
res => return res,
}
// Wait until the I/O handle becomes writable.
optimistic(self.writable()).await?;
}
}