Hey I just met you, and this is crazy, but here's my callback.
Hey I just met you, and this is crazy, but here's my callback, so definitely call it once, and once only.
This tiny module is meant to help debug pesky asynchronous code by making sure your callbacks are called just once. It also checks if the given callback is undefined or if it's called in the same event loop.
This is meant to be used during testing, not production code. But could be used to help debug.
var callme = require'callme';callback = callmecallback;someIOa bif err callbackerr;result = permuteTheResultresult;// this will throw if there is an error since it will be// the second time the callback is called.// a `return` was forgotten on the error check above.callbackerr result;;
callme function returned is also an instance of
EventEmitter. If you prefer to listen to the
error event instead, you can do so.
callback = callmecallback;callbackon'error'// do something with `err`;someIOa b// etc;
It also supports a
timeout option, make sure your callbacks are definitely called.
callback = callmecallback 2000; // set timeout to 2 secondscallbackon'error'// this will fire in 2 seconds since `callback` is never called;
npm install callme
Tests are written with mocha