Skip to content

Calls a callback once after platform-independent next tick

License

Notifications You must be signed in to change notification settings

kmalakoff/call-once-next-tick

Repository files navigation

call-once-next-tick

Calls a callback once after platform-independent next tick.

var next = once('call-once-next-tick');
var assert = require('assert');

var results = [];

function addResults() {
  results.push(arguments);
}

var callback1 = once(addResults);
assert.ok(!results.length);
callback1('error', 'value1', 'value2');
assert.ok(!results.length);

setImmediate(function () {
  assert.equal(results.length, 1);
  callback1('error', 'value1', 'value2');
  assert.equal(results.length, 1);
});

About

Calls a callback once after platform-independent next tick

Resources

License

Stars

Watchers

Forks

Packages

No packages published