cancellation_token
Version, currently main branch1 version
- main branchlatestFeb 12, 2025
github.com/nobodywasishere/cancellation_token.cr
No description declared in shard.yml.
1 stars
0 dependents
License: MIT
Installation
# Add this to your shard.yml
dependencies:
cancellation_token:
github: nobodywasishere/cancellation_token.cr
branch: mainmain is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
>= 1.14.0- License
- MIT
- Author
- Margret Riegert
Dependencies
This version declares no dependencies.
README
CancellationToken
Simple cancellation token using channels, based on the VS Code CancellationToken.
Installation
-
Add the dependency to your
shard.yml:dependencies: cancellation_token: github: nobodywasishere/cancellation_token -
Run
shards install
Usage
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
end
puts "hello world"
sleep(1.second)
# Do fiber work here
end
end
# Later on, if desired, cancel the token
token_source.cancel
Contributing
- Fork it (https://github.com/nobodywasishere/cancellation_token/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Margret Riegert - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
main- Seen
- Feb 12, 2025
- Crystal
>= 1.14.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/nobodywasishere/cancellation_token.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 15, 2026
- Synced
- Aug 15, 2026
- Versions
- 1