sync: add owned future for CancellationToken (#5153)

This commit is contained in:
Jiahao XU
2022-11-21 15:03:09 +00:00
committed by GitHub
parent f15d14ee91
commit 304b5152a7
4 changed files with 171 additions and 1 deletions
@@ -24,6 +24,27 @@ fn cancel_token() {
});
}
#[test]
fn cancel_token_owned() {
loom::model(|| {
let token = CancellationToken::new();
let token1 = token.clone();
let th1 = thread::spawn(move || {
block_on(async {
token1.cancelled_owned().await;
});
});
let th2 = thread::spawn(move || {
token.cancel();
});
assert_ok!(th1.join());
assert_ok!(th2.join());
});
}
#[test]
fn cancel_with_child() {
loom::model(|| {