1
- //! An asynchronously awaitable `CancellationToken`.
1
+ //! An asynchronously awaitable [ `CancellationToken`] .
2
2
//! The token allows to signal a cancellation request to one or more tasks.
3
3
pub ( crate ) mod guard;
4
4
pub ( crate ) mod guard_ref;
@@ -112,7 +112,7 @@ impl core::fmt::Debug for CancellationToken {
112
112
}
113
113
114
114
impl Clone for CancellationToken {
115
- /// Creates a clone of the `CancellationToken` which will get cancelled
115
+ /// Creates a clone of the [ `CancellationToken`] which will get cancelled
116
116
/// whenever the current token gets cancelled, and vice versa.
117
117
fn clone ( & self ) -> Self {
118
118
tree_node:: increase_handle_refcount ( & self . inner ) ;
@@ -135,15 +135,15 @@ impl Default for CancellationToken {
135
135
}
136
136
137
137
impl CancellationToken {
138
- /// Creates a new `CancellationToken` in the non-cancelled state.
138
+ /// Creates a new [ `CancellationToken`] in the non-cancelled state.
139
139
pub fn new ( ) -> CancellationToken {
140
140
CancellationToken {
141
141
inner : Arc :: new ( tree_node:: TreeNode :: new ( ) ) ,
142
142
}
143
143
}
144
144
145
- /// Creates a `CancellationToken` which will get cancelled whenever the
146
- /// current token gets cancelled. Unlike a cloned `CancellationToken`,
145
+ /// Creates a [ `CancellationToken`] which will get cancelled whenever the
146
+ /// current token gets cancelled. Unlike a cloned [ `CancellationToken`] ,
147
147
/// cancelling a child token does not cancel the parent token.
148
148
///
149
149
/// If the current token is already cancelled, the child token will get
@@ -206,12 +206,18 @@ impl CancellationToken {
206
206
tree_node:: is_cancelled ( & self . inner )
207
207
}
208
208
209
- /// Returns a `Future` that gets fulfilled when cancellation is requested.
209
+ /// Returns a [`Future`] that gets fulfilled when cancellation is requested.
210
+ ///
211
+ /// Equivalent to:
212
+ ///
213
+ /// ```ignore
214
+ /// async fn cancelled(&self);
215
+ /// ```
210
216
///
211
217
/// The future will complete immediately if the token is already cancelled
212
218
/// when this method is called.
213
219
///
214
- /// # Cancel safety
220
+ /// # Cancellation safety
215
221
///
216
222
/// This method is cancel safe.
217
223
pub fn cancelled ( & self ) -> WaitForCancellationFuture < ' _ > {
@@ -221,30 +227,36 @@ impl CancellationToken {
221
227
}
222
228
}
223
229
224
- /// Returns a `Future` that gets fulfilled when cancellation is requested.
230
+ /// Returns a [`Future`] that gets fulfilled when cancellation is requested.
231
+ ///
232
+ /// Equivalent to:
233
+ ///
234
+ /// ```ignore
235
+ /// async fn cancelled_owned(self);
236
+ /// ```
225
237
///
226
238
/// The future will complete immediately if the token is already cancelled
227
239
/// when this method is called.
228
240
///
229
241
/// The function takes self by value and returns a future that owns the
230
242
/// token.
231
243
///
232
- /// # Cancel safety
244
+ /// # Cancellation safety
233
245
///
234
246
/// This method is cancel safe.
235
247
pub fn cancelled_owned ( self ) -> WaitForCancellationFutureOwned {
236
248
WaitForCancellationFutureOwned :: new ( self )
237
249
}
238
250
239
- /// Creates a `DropGuard` for this token.
251
+ /// Creates a [ `DropGuard`] for this token.
240
252
///
241
253
/// Returned guard will cancel this token (and all its children) on drop
242
254
/// unless disarmed.
243
255
pub fn drop_guard ( self ) -> DropGuard {
244
256
DropGuard { inner : Some ( self ) }
245
257
}
246
258
247
- /// Creates a `DropGuardRef` for this token.
259
+ /// Creates a [ `DropGuardRef`] for this token.
248
260
///
249
261
/// Returned guard will cancel this token (and all its children) on drop
250
262
/// unless disarmed.
@@ -253,10 +265,10 @@ impl CancellationToken {
253
265
}
254
266
255
267
/// Runs a future to completion and returns its result wrapped inside of an `Option`
256
- /// unless the `CancellationToken` is cancelled. In that case the function returns
268
+ /// unless the [ `CancellationToken`] is cancelled. In that case the function returns
257
269
/// `None` and the future gets dropped.
258
270
///
259
- /// # Cancel safety
271
+ /// # Cancellation safety
260
272
///
261
273
/// This method is only cancel safe if `fut` is cancel safe.
262
274
pub async fn run_until_cancelled < F > ( & self , fut : F ) -> Option < F :: Output >
@@ -299,12 +311,12 @@ impl CancellationToken {
299
311
}
300
312
301
313
/// Runs a future to completion and returns its result wrapped inside of an `Option`
302
- /// unless the `CancellationToken` is cancelled. In that case the function returns
314
+ /// unless the [ `CancellationToken`] is cancelled. In that case the function returns
303
315
/// `None` and the future gets dropped.
304
316
///
305
317
/// The function takes self by value and returns a future that owns the token.
306
318
///
307
- /// # Cancel safety
319
+ /// # Cancellation safety
308
320
///
309
321
/// This method is only cancel safe if `fut` is cancel safe.
310
322
pub async fn run_until_cancelled_owned < F > ( self , fut : F ) -> Option < F :: Output >
0 commit comments