mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Impl AutoAbortJoinHandle::new
& make its field private
plus change all its users to use its new APIs. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
f41391a53c
commit
d9bcca8b78
2 changed files with 12 additions and 6 deletions
|
@ -64,13 +64,13 @@ impl MultiFetcher {
|
|||
.map(|fetcher| {
|
||||
(
|
||||
fetcher.clone(),
|
||||
AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })),
|
||||
AutoAbortJoinHandle::new(tokio::spawn(async move { fetcher.check().await })),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
for (fetcher, mut handle) in handles {
|
||||
match (&mut handle.0).await {
|
||||
for (fetcher, handle) in handles {
|
||||
match handle.await {
|
||||
Ok(Ok(true)) => return Some(fetcher),
|
||||
Ok(Ok(false)) => (),
|
||||
Ok(Err(err)) => {
|
||||
|
|
|
@ -246,7 +246,7 @@ impl AsyncFileWriter {
|
|||
let mut file = fs::File::create(path)?;
|
||||
let (tx, mut rx) = mpsc::channel::<Bytes>(100);
|
||||
|
||||
let handle = AutoAbortJoinHandle(task::spawn_blocking(move || {
|
||||
let handle = AutoAbortJoinHandle::new(task::spawn_blocking(move || {
|
||||
while let Some(bytes) = rx.blocking_recv() {
|
||||
file.write_all(&*bytes)?;
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ impl AsyncFileWriter {
|
|||
}
|
||||
|
||||
async fn wait(handle: &mut AutoAbortJoinHandle<io::Result<()>>) -> io::Result<()> {
|
||||
match (&mut handle.0).await {
|
||||
match handle.await {
|
||||
Ok(res) => res,
|
||||
Err(join_err) => Err(io::Error::new(io::ErrorKind::Other, join_err)),
|
||||
}
|
||||
|
@ -308,7 +308,13 @@ impl AsyncFileWriter {
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AutoAbortJoinHandle<T>(pub task::JoinHandle<T>);
|
||||
pub struct AutoAbortJoinHandle<T>(task::JoinHandle<T>);
|
||||
|
||||
impl<T> AutoAbortJoinHandle<T> {
|
||||
pub fn new(handle: task::JoinHandle<T>) -> Self {
|
||||
Self(handle)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Drop for AutoAbortJoinHandle<T> {
|
||||
fn drop(&mut self) {
|
||||
|
|
Loading…
Add table
Reference in a new issue