remove extra spinning from mpsc::Receiver::recv
This commit is contained in:
parent
cb394c026a
commit
8c17a3e7cb
@ -378,22 +378,12 @@ impl<T> Channel<T> {
|
||||
/// Receives a message from the channel.
|
||||
pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
|
||||
let token = &mut Token::default();
|
||||
loop {
|
||||
// Try receiving a message several times.
|
||||
let backoff = Backoff::new();
|
||||
loop {
|
||||
if self.start_recv(token) {
|
||||
let res = unsafe { self.read(token) };
|
||||
return res.map_err(|_| RecvTimeoutError::Disconnected);
|
||||
}
|
||||
|
||||
if backoff.is_completed() {
|
||||
break;
|
||||
} else {
|
||||
backoff.snooze();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(d) = deadline {
|
||||
if Instant::now() >= d {
|
||||
return Err(RecvTimeoutError::Timeout);
|
||||
|
@ -417,9 +417,6 @@ impl<T> Channel<T> {
|
||||
/// Receives a message from the channel.
|
||||
pub(crate) fn recv(&self, deadline: Option<Instant>) -> Result<T, RecvTimeoutError> {
|
||||
let token = &mut Token::default();
|
||||
loop {
|
||||
// Try receiving a message several times.
|
||||
let backoff = Backoff::new();
|
||||
loop {
|
||||
if self.start_recv(token) {
|
||||
unsafe {
|
||||
@ -427,13 +424,6 @@ impl<T> Channel<T> {
|
||||
}
|
||||
}
|
||||
|
||||
if backoff.is_completed() {
|
||||
break;
|
||||
} else {
|
||||
backoff.snooze();
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(d) = deadline {
|
||||
if Instant::now() >= d {
|
||||
return Err(RecvTimeoutError::Timeout);
|
||||
|
Loading…
x
Reference in New Issue
Block a user