Crates.io | min-cancel-token |
lib.rs | min-cancel-token |
version | 0.1.0 |
source | src |
created_at | 2022-01-08 22:00:30.499607 |
updated_at | 2022-01-08 22:00:30.499607 |
description | A cancellation token interface and implementation |
homepage | https://github.com/Matthias247/min-cancel-token |
repository | https://github.com/Matthias247/min-cancel-token |
max_upload_size | |
id | 510559 |
size | 37,804 |
This crate provides a standarized interface/trait for a CancellationToken
, which
can be used by libraries and applications to react to cancellation events.
The CancellationToken
interface can be interacted with in 2 ways:
The overall interface thereby follows the design of C++ https://en.cppreference.com/w/cpp/thread/stop_token. However only the interface is standardized here, and no concrete implementation.
This has the benefit that different platforms and applications can provide implementations which fit them best. E.g.
CancellationToken
implementations,
which are here provided as part of the std_impls
module.CancellationToken
per task.CancellationToken
s inside the task state for each task,
and thereby enable graceful per-task cancellation.See A case for CancellationTokens
CancellationTokens are designed to be composable. The cancellation of a higher level task (e.g. the whole application) can trigger the cancellation of lower level tasks (e.g. performing a database query). That again could lead to cancellation of a particular IO call, like waiting to read data from a TCP connection.
As a consequence of this, most parts of applications might not have to be cancellation aware - it will be sufficient if long-running lower-level calls (e.g. socket and disk IO) understand cancellation and return errors if cancellation is initiated.
This repository and crate is currently an experiment and a base for discussion. It's not in a final state, and the interface provided by the crate might change.
Licensed under either of
at your option.