mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
sync: fix CancellationToken failing to cancel the ready futures (#7462)
This patch fixes an issue where the `CancellationToken::run_until_cancelled` never cancels the `Future` that returns `Ready` at the first `poll`. --------- Co-authored-by: Luca BRUNO <[email protected]>
This commit is contained in:
co-authored by
Luca BRUNO
parent
0a3fe46086
commit
6d868d96ce
@@ -492,6 +492,21 @@ fn run_until_cancelled_test() {
|
||||
fut.as_mut().poll(&mut Context::from_waker(&waker))
|
||||
);
|
||||
}
|
||||
|
||||
// Do not poll the future when token is already cancelled.
|
||||
{
|
||||
let token = CancellationToken::new();
|
||||
|
||||
let fut = token.run_until_cancelled(async { panic!("fut polled after cancellation") });
|
||||
pin!(fut);
|
||||
|
||||
token.cancel();
|
||||
|
||||
assert_eq!(
|
||||
Poll::Ready(None),
|
||||
fut.as_mut().poll(&mut Context::from_waker(&waker))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user