0.1.0 • Published 9 years ago

cancelable-group v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

npm

cancelable-group

Build Status Dependency Status

Create groups of callbacks that can be canceled in one go.

Think FGRibreau/cancelable for groups or substack/node-toss without timeouts and the extra stuff. This module is focused on one thing.

Example

var cancelableGroup = require('cancelable-group');

var group = cancelableGroup();

asyncFunction1(arg1, arg2, group(function (err, data) {
  // Won't fire after cancel() call.
}));

asyncFunction2(arg1, arg2, group(function (err, data) {
  // Won't fire after cancel() call.
}));

someOtherFunction(function () {
  // ...
  group.cancel();
}));

API

group = cancelableGroup()

Creates new cancelable group.

group(func)

Returns a wrapper function that is equivalent to func unless the group is canceled. Then it becomes a no-op.

group()

group.cancel()

Cancels the group.

Install

npm install cancelable-group

License

MIT