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.31.tar.gz
(9.4 kB
view details)
Built Distribution
cantok-0.0.31-py3-none-any.whl
(11.9 kB
view details)
File details
Details for the file cantok-0.0.31.tar.gz
.
File metadata
- Download URL: cantok-0.0.31.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e53220fae103a6e103623a3079ddd19cd52f7c6538f7034b31f34660486a2dc |
|
MD5 | 4cc88894b29f6e318a44f02ab72713bf |
|
BLAKE2b-256 | 1b7167dc7fe9632e0cd21c7675d329b6a44c268392e09c83eb31fd9d52662c79 |
File details
Details for the file cantok-0.0.31-py3-none-any.whl
.
File metadata
- Download URL: cantok-0.0.31-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 | 02c225fc079dbd9b367224bb85c5722789313f3036f9b3b82c9117af252fdc15 |
|
MD5 | 4ad65c69439fa0457f6cc3088c9c8d66 |
|
BLAKE2b-256 | 1c6d21e00a0fb8230cdcab9ef0b36b309493a9659e13522a26a3fe9a1c20def5 |