Metadata-Version: 2.1
Name: cancel-token
Version: 0.1.3
Summary: Simple CancellationToken
Home-page: https://github.com/Novakov/py-cancel-token
Author: Maciej Nowak
License: UNKNOWN
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Utilities
Description-Content-Type: text/markdown

CancellationToken for Python
---

This library provide simple cancellation token. 

# Usage

First create token
```python
from cancel_token import CancellationToken

token = CancellationToken()
```

At any point in time you can check if token has been cancelled:
```python
if token.cancelled:
    print('Operation already cancelled')
    return None  
```

To cancel token call its `cancel` method:
```python
token.cancel()
assert token.cancelled
```

It is also possible to add callbacks that will be called on when token is cancelled:
```python
def handler():
    print('Operation has been cancelled')

token.on_cancel(handler)
```

**Note**:
* If token is already cancelled, callback will be invoked immediately.
* All registered callbacks will be called sequentially during `cancel` call.
* Callback throwing exception will prevent remaining callbacks from calling. However token will be cancelled
* During callback invocation token is already cancelled
* It is possible to add callback from within callback
* Removing callback from within callback **will not** prevent its execution



