https://github.com/pirxpilot/guard
Trivial guard: triggers callback when internal counter reaches 0.
https://github.com/pirxpilot/guard
Last synced: over 1 year ago
JSON representation
Trivial guard: triggers callback when internal counter reaches 0.
- Host: GitHub
- URL: https://github.com/pirxpilot/guard
- Owner: pirxpilot
- License: mit
- Created: 2012-12-17T07:20:27.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2022-06-05T07:52:58.000Z (about 4 years ago)
- Last Synced: 2025-01-29T06:53:04.454Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](http://travis-ci.org/code42day/guard)
[](http://badge.fury.io/js/guard)
# guard
Trivial guard: triggers callback when internal counter reaches 0.
## API
Create ```guard``` passing callback function. Call ```on()``` and ```off()``` to increase and
decrease internal counter.
g = guard(function() {
console.log('Done...')
});
g.on();
g.on();
g.off();
g.off(); // prints 'Done...'
You can initialize the counter when creating a new guard.
g = guard(function() {
console.log('Done...')
}, 2);
g.on();
// call off 3 times
g.off();
g.off();
g.off(); // prints 'Done...'
In addition to `done` callback you can setup callbacks when counter reaches a certain value during
`on` or `off`
g = guard()
.onCallback(100, function() {
// called when internal counter is 100 after increment
})
.offCallback(10, function() {
// called when internal counter is 10 after decrement
});
## License
MIT