counter_safe
Version, currently 0.1.14 versions
- 0.1.3latestMar 27, 2021
- 0.1.2not indexedMar 27, 2021
- 0.1.1not indexedMar 27, 2021
- 0.1.0not indexedMar 27, 2021
github.com/drhuffman12/counter_safe
No description declared in shard.yml.
Nothing has been indexed for 0.1.1 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
counter_safe:
github: drhuffman12/counter_safe
version: ~> 0.1.1Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.1. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
counter_safe
Thread safe counters:
- CounterSafe::Shared -- e.g.: global shared counters
- CounterSafe::Exclusive -- e.g.: class-local exclusive counters
Based on and with much thanks to: Comparing Crystal’s concurrency with that of Go (Part II)
Installation
- Add the dependency to your
shard.yml:
dependencies:
counter_safe:
github: drhuffman12/counter_safe
- Run
shards install... orshards install --ignore-crystal-version
Usage
require "counter_safe"
Example Usage:
- Shared counters:
cs1 = CounterSafe::Shared.new
cs2 = CounterSafe::Shared.new
(1..1000).each {
rand < 0.25 ? spawn cs1.inc("someKey") : spawn cs2.inc("someKey")
}
sleep 1.second
puts cs1.value("someKey")
puts cs2.value("someKey") #=> Should be the same as 'cs1.value("someKey")'
- Exclusive counters:
ce1 = CounterSafe::Exclusive.new
ce2 = CounterSafe::Exclusive.new
(1..1000).each {
rand < 0.25 ? spawn ce1.inc("someKey") : spawn ce2.inc("someKey")
}
puts ce1.value("someKey")
puts ce2.value("someKey") #=> Should be DIFFERENT than as 'cs1.value("someKey")'
See also API doc's at: https://drhuffman12.github.io/counter_safe
Development
REMINDER: Be sure to do separate PR's for: (a) one or more PR(s) for 'regular' src/spec changes
# misc changes, then (before pushing your changes) run:
scripts/reformat
crystal spec
(b) followed by one PR for version bump and update docs
# bump version in `shards.yml`, then (before pushing your changes) run:
scripts/regen_docs
Contributing
- Fork it (https://github.com/your-github-user/counter_safe/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
- Daniel Huffman - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.1- Tagged
- Mar 27, 2021
- Commit
53b14efe8ebe- Indexed
- not yet
Dependents
Repository
github.com/drhuffman12/counter_safe
Metadata
- Created
- Aug 12, 2026
- Updated
- Sep 27, 2026
- Synced
- Sep 27, 2026
- Versions
- 4