Implementation of the "Cancellation Token" pattern
Project description
Cancellation Token is a pattern that allows us to refuse to continue calculations that we no longer need. It is implemented out of the box in many programming languages, for example in C# and in Go. However, there was still no sane implementation in Python, until the cantok library appeared.
Quick start
Install it:
pip install cantok
And use:
from random import randint
from cantok import ConditionToken, CounterToken, TimeoutToken
token = ConditionToken(lambda: randint(1, 100_000) == 1984) + CounterToken(400_000, direct=False) + TimeoutToken(1)
counter = 0
while token:
counter += 1
print(counter)
Read more in the documentation!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cantok-0.0.30.tar.gz
(9.3 kB
view details)
Built Distribution
cantok-0.0.30-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file cantok-0.0.30.tar.gz
.
File metadata
- Download URL: cantok-0.0.30.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2d68a5aa170e369ccc7ba3438ffadefdaf58184f594e499a2905764f063ee0a |
|
MD5 | a8af7d22dd2c3177b72224cf1bcd99e8 |
|
BLAKE2b-256 | 88a1adf438f8f4e0e0e7e0b662877c1369937ced28f83d1638156fa1c72cf114 |
File details
Details for the file cantok-0.0.30-py3-none-any.whl
.
File metadata
- Download URL: cantok-0.0.30-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7372ac50da2f3760b07396c10fe3e8a38fe0e13eb0e929a5cac062e4102d422 |
|
MD5 | 3b4a5f1b8532fd11ddd614e1e1f5e5b3 |
|
BLAKE2b-256 | 755640499638601b0a4b88784f6034d570656a3c7a65e4fc8eb9478ea2398022 |