mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-24 14:28:42 +00:00
Optimize use of tokio::select!
: Use biased selection (#580)
as there is no need to randomize the first one to be polled. For `cancel_on_user_sig_term` and `StreamReadable::fill_buf`, the cancellation future should always to be polled first so that user would feel responsive. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
af82f1021c
commit
ff737730f4
2 changed files with 10 additions and 2 deletions
|
@ -122,10 +122,12 @@ where
|
|||
let option = self.handle.block_on(async {
|
||||
if let Some(cancellation_future) = self.cancellation_future.as_mut() {
|
||||
tokio::select! {
|
||||
res = next_stream(&mut self.stream) => res,
|
||||
biased;
|
||||
|
||||
res = cancellation_future => {
|
||||
Err(res.err().unwrap_or_else(|| io::Error::from(DownloadError::UserAbort)))
|
||||
},
|
||||
res = next_stream(&mut self.stream) => res,
|
||||
}
|
||||
} else {
|
||||
next_stream(&mut self.stream).await
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue