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.29.tar.gz
(9.3 kB
view details)
Built Distribution
cantok-0.0.29-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file cantok-0.0.29.tar.gz
.
File metadata
- Download URL: cantok-0.0.29.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 | 218564845608bd51aa59a530ca13ee29d14162315ee61901abd3a7fd775844ab |
|
MD5 | 5d264970aada670ab93561e93fa17dc9 |
|
BLAKE2b-256 | e0baaf713461cb8fd319689f5eec0809d01d166bd7dd72ad178068fa36f7e521 |
File details
Details for the file cantok-0.0.29-py3-none-any.whl
.
File metadata
- Download URL: cantok-0.0.29-py3-none-any.whl
- Upload date:
- Size: 11.8 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 | 2af02cf9b9bde929459d1d3ad769687abeae3bc21b27c5caca4dcd75dadf723a |
|
MD5 | 57d284f5a9b0903eb6b6a341ee4e08ab |
|
BLAKE2b-256 | 9178baccbe189bb27387bfe6c2fab49b1b4ad847c9ad088c70dfdc210bd58af0 |