Skip to content

Make future::JoinHandle::abort actually cancel task #91

@bkragl

Description

@bkragl

The implementation of abort in #87 as detaching the task does not seem right, because detached tasks may still continue to run. Consider the following test, which should not fail but currently does.

#[test]
fn join_handle_abort_bug() {
    check_dfs(
        || {
            let (sender, receiver) = futures::channel::oneshot::channel();
            let t = future::spawn({
                async move {
                    receiver.await.unwrap();
                    panic!("should not get here");
                }
            });
            t.abort();
            sender.send(()).unwrap();
            shuttle::thread::yield_now();
        },
        None,
    );
}

(The yield_now is needed because otherwise the main task would immediately finish, in which case also the execution finishes because there are no attached tasks left.)

We need a way to actually cancel a task, which drops its continuation and returns a JoinError indicating cancellation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions