https://github.com/nobodywasishere/cancellation_token.cr
https://github.com/nobodywasishere/cancellation_token.cr
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/nobodywasishere/cancellation_token.cr
- Owner: nobodywasishere
- License: mit
- Created: 2024-12-18T17:22:12.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-02-12T21:50:57.000Z (4 months ago)
- Last Synced: 2025-05-13T13:19:53.073Z (about 1 month ago)
- Language: Crystal
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CancellationToken
Simple cancellation token using channels, based on the VS Code [CancellationToken](https://code.visualstudio.com/api/references/vscode-api#CancellationToken).
## Installation
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
cancellation_token:
github: nobodywasishere/cancellation_token
```2. Run `shards install`
## Usage
```crystal
require "cancellation_token"# Create a new token source
token_source = CancellationTokenSource.new
token = token_source.token# Spawn a fiber that checks the token to see if it should stop
spawn do
loop do
# Check to see if the fiber should stop
if token.cancelled?
break
endputs "hello world"
sleep(1.second)
# Do fiber work here
end
end# Later on, if desired, cancel the token
token_source.cancel```
## Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Contributors
- [Margret Riegert](https://github.com/nobodywasishere) - creator and maintainer