Skip to content

Commit 2d2b4e7

Browse files
authored
Merge pull request #59 from mutating/develop
0.0.42
2 parents 81f3235 + 4e08e3d commit 2d2b4e7

10 files changed

Lines changed: 716 additions & 1 deletion

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "cantok"
7-
version = "0.0.41"
7+
version = "0.0.42"
88
authors = [{ name = "Evgeniy Blinov", email = "zheni-b@yandex.ru" }]
99
description = 'Implementation of the "Cancellation Token" pattern'
1010
readme = "README.md"

tests/examples/test_examples.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
counter = 0
77

88
def test_cancel_simple_token_with_function_and_thread():
9+
"""
10+
A quick-start Condition, Counter, and Timeout composition can stop a worker thread.
11+
12+
The worker receives the composed token, performs some work while `.cancelled`
13+
is false, and exits once the random condition, indirect counter poll, or
14+
timeout cancels the shared token.
15+
"""
916
def function(token):
1017
global counter # noqa: PLW0603
1118
while not token.cancelled:
@@ -20,6 +27,12 @@ def function(token):
2027

2128

2229
def test_cancel_simple_token_with_function_and_thread_2():
30+
"""
31+
A quick-start Condition, Counter, and Timeout composition can be a truthy loop guard.
32+
33+
The loop makes progress while the composed token is active, then stops once the
34+
random condition, indirect counter poll, or timeout cancels it.
35+
"""
2336
token = ConditionToken(lambda: randint(1, 100_000) == 1984) + CounterToken(400_000, direct=False) + TimeoutToken(1)
2437
counter = 0
2538

tests/units/test_errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313

1414

1515
def test_exception_inheritance_hierarchy():
16+
"""Specialized cancellation errors share the common cancellation base class."""
1617
assert issubclass(ConditionCancellationError, CancellationError)
1718
assert issubclass(TimeoutCancellationError, CancellationError)
1819
assert issubclass(CounterCancellationError, CancellationError)
1920
assert issubclass(ImpossibleCancelError, CancellationError)
2021

2122

2223
def test_exception_inheritance_hierarchy_from_view_of_tokens_classes():
24+
"""
25+
Concrete token classes expose their configured cancellation exception types.
26+
27+
Specialized token exceptions remain compatible with the base error exposed by
28+
SimpleToken, and DefaultToken exposes the error used by its impossible-cancel
29+
paths.
30+
"""
2331
assert issubclass(ConditionToken.exception, SimpleToken.exception)
2432
assert issubclass(TimeoutToken.exception, SimpleToken.exception)
2533
assert issubclass(CounterToken.exception, SimpleToken.exception)

0 commit comments

Comments
 (0)