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

Notify: basic example intermittently fails #4210

Closed
davidcopp opened this issue Nov 2, 2021 · 1 comment · Fixed by #4212
Closed

Notify: basic example intermittently fails #4210

davidcopp opened this issue Nov 2, 2021 · 1 comment · Fixed by #4212
Labels
A-tokio Area: The main tokio crate M-sync Module: tokio/sync T-docs Topic: documentation

Comments

@davidcopp
Copy link

When running the given Notify - basic example (tokio 1.13.0 on MacOs 11.6), the correct output is

sending notification
received notification

but more often I get only

sending notification

Joining the spawned task fixes the problem:

    let join = tokio::spawn(async move {
        notify2.notified().await;
        println!("received notification");
    });

    println!("sending notification");
    notify.notify_one();
    println!("joining spawned task");
    join.await.expect("spawn failed");
    println!("spawned task completed");

Could be a doc or a real bug, not sure.

@Darksonn Darksonn added A-tokio Area: The main tokio crate M-sync Module: tokio/sync T-docs Topic: documentation labels Nov 2, 2021
@Darksonn
Copy link
Contributor

Darksonn commented Nov 2, 2021

Thanks for reporting. This is a problem in the documentation - the spawned task is killed when main returns, so it may never get to run.

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 M-sync Module: tokio/sync T-docs Topic: documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants