mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-30 00:00:16 +02:00
sync: implement cancellation token getter for drop guard (#8226)
This commit is contained in:
@@ -10,6 +10,13 @@ pub struct DropGuard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DropGuard {
|
impl DropGuard {
|
||||||
|
/// Returns a reference to the cancellation token wrapped by this guard.
|
||||||
|
pub fn token(&self) -> &CancellationToken {
|
||||||
|
self.inner
|
||||||
|
.as_ref()
|
||||||
|
.expect("`inner` can only be None in a destructor")
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns stored cancellation token and removes this drop guard instance
|
/// Returns stored cancellation token and removes this drop guard instance
|
||||||
/// (i.e. it will no longer cancel token). Other guards for this token
|
/// (i.e. it will no longer cancel token). Other guards for this token
|
||||||
/// are not affected.
|
/// are not affected.
|
||||||
|
|||||||
@@ -13,6 +13,13 @@ pub struct DropGuardRef<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DropGuardRef<'a> {
|
impl<'a> DropGuardRef<'a> {
|
||||||
|
/// Returns a reference to the cancellation token wrapped by this guard.
|
||||||
|
pub fn token(&self) -> &CancellationToken {
|
||||||
|
self.inner
|
||||||
|
.as_ref()
|
||||||
|
.expect("`inner` can only be None in a destructor")
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns stored cancellation token and removes this drop guard instance
|
/// Returns stored cancellation token and removes this drop guard instance
|
||||||
/// (i.e. it will no longer cancel token). Other guards for this token
|
/// (i.e. it will no longer cancel token). Other guards for this token
|
||||||
/// are not affected.
|
/// are not affected.
|
||||||
|
|||||||
Reference in New Issue
Block a user