Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider implementing JoinHandle::try_join #6488

Open
andreastedile opened this issue Apr 15, 2024 · 1 comment
Open

Consider implementing JoinHandle::try_join #6488

andreastedile opened this issue Apr 15, 2024 · 1 comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task

Comments

@andreastedile
Copy link
Contributor

Consider the following code using a JoinHandle:

if handle.is_finished() {
    let result = handle.await;
    match result {
        Ok(result) => {}
        Err(error) => {}
    }
}

I think that it would a bit more ergonomic to be able to just do:

match handle.try_join() {
    Some(Ok(result)) => {} // Task has completed successfully
    Some(Err(error)) => {} // Task has completed with error
    None => {} // Task has not completed yet
}

As pointed out on Discord, there is the issue that that handle.await will panic if called after handle.try_join returns not None.

@andreastedile andreastedile added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Apr 15, 2024
@Darksonn Darksonn added the M-task Module: tokio/task label Apr 15, 2024
@dd-dreams
Copy link

dd-dreams commented Apr 25, 2024

there is the issue that that handle.await will panic if called after handle.try_join returns not None

Though you should call handle.try_join().await. Why would you call handle.await after try_join?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-task Module: tokio/task
Projects
None yet
Development

No branches or pull requests

3 participants