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.26.tar.gz
(8.7 kB
view details)
Built Distribution
cantok-0.0.26-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file cantok-0.0.26.tar.gz
.
File metadata
- Download URL: cantok-0.0.26.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa07acaf9c7a2a25b2170fcc8559656cfe275b04547751488947a36fcb6113fe |
|
MD5 | a5e1caeba82b3838c3acd3df3e7315e7 |
|
BLAKE2b-256 | c0c2efdf5a7e3e057547e61b2e9d56ddbfe2228a1cd44ef97c9acb966a2605b5 |
File details
Details for the file cantok-0.0.26-py3-none-any.whl
.
File metadata
- Download URL: cantok-0.0.26-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97bd000cd740dfd355e43e6246c09624c6617004f300c433b8aff89c33627bd1 |
|
MD5 | 247f285f424b664bc4df387e20ffc30b |
|
BLAKE2b-256 | b9214c8ef3ff31740e4fb4a2f85dbb5092ec89984efd5934816c448ca3dfb88a |