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.27.tar.gz
(8.7 kB
view details)
Built Distribution
cantok-0.0.27-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file cantok-0.0.27.tar.gz
.
File metadata
- Download URL: cantok-0.0.27.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 | 0efc924f47d90851b8e83ed49170213ac76ff3da34b141d5d6db9f3fca6cde1f |
|
MD5 | cf90f2ca566989ba3fc48deb346b2eb4 |
|
BLAKE2b-256 | eeadc84b819b3cf725487ef60f5ec9eac8fada8174dd1a6792f3ef9b0e810ad0 |
File details
Details for the file cantok-0.0.27-py3-none-any.whl
.
File metadata
- Download URL: cantok-0.0.27-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 | 8939fc3b28f58966d84e750a7a05f417dc2eba8f3d4dbc5f1cc759456e8bfb0f |
|
MD5 | a94441f0b979597d525d0ef77ac672ff |
|
BLAKE2b-256 | 6de08c77cd65c203c8e60cb10717da5440d8aacb7c1ec055fea4e614eccc6593 |