https://github.com/strilanc/java-cancel-tokens
An implementation of a cancel token, an object to conveniently register and invoke cleanup methods, in java.
https://github.com/strilanc/java-cancel-tokens
Last synced: 4 months ago
JSON representation
An implementation of a cancel token, an object to conveniently register and invoke cleanup methods, in java.
- Host: GitHub
- URL: https://github.com/strilanc/java-cancel-tokens
- Owner: Strilanc
- License: mit
- Created: 2014-05-27T02:31:44.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2014-05-27T02:52:58.000Z (about 12 years ago)
- Last Synced: 2025-06-12T18:11:28.351Z (12 months ago)
- Homepage:
- Size: 145 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Java Cancel Tokens
==================
This library implements a `CancelToken`, a tool for making cleanup easier. It is licensed under the MIT license.
Installation
============
Currently the library is a single file, [`src/com/strilanc/async/CancelToken.java`](https://github.com/Strilanc/Java-Cancel-Tokens/blob/master/src/com/strilanc/async/CancelToken.java), so installation consists of copying that file into your project and changing the package if it annoys you. I will expose it as a proper maven (or other) package if there is interest.
Exposed API
===========
- **CancelToken**
- *static* **cancelled()**: Returns an already-cancelled token.
- *static* **immortal()**: Returns an already-immortal token.
- **getState()**: Determines whether the cancel token is still-cancellable, cancelled, or immortal.
- **whenCancelled(callback)**: Registers a callback to be run when the token is cancelled. The callback runs right away if the token is already cancelled.
- **whenCancelledBefore(callback, otherToken)**: Registers a callback to be run when the receiving token is cancelled, unless the other token is cancelled first.
- **CancelToken.Source**
- *(constructor)* **()**: Creates a new source that controls a new token.
- **getToken()**: Returns the token controlled by the source.
- **cancel()**: Attempts to cancel the controlled token, returning false if it was not still cancellable.