guard

0.1.2 • Public • Published

Build Status NPM version

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.2
    47
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.2
    47
  • 0.1.1
    6
  • 0.1.0
    5
  • 0.0.1
    0

Package Sidebar

Install

npm i guard

Weekly Downloads

58

Version

0.1.2

License

MIT

Last publish

Collaborators

  • pirxpilot