@rainder/callbacks
v0.3.2
Published
callbacks with a timeout
Downloads
9
Readme
Callbacks
Callback implementation with native Promises
Example
const co = require('co');
const Callbacks = require('@rainder/callbacks');
const callbacks = new Callbacks();
co(function *() {
//define data to work with
const ID = '10432';
const DATA = 'data1';
//create a callback
const promise = callbacks.create(ID);
setTimeout(function () {
callbacks.getCallback(ID).resolve(DATA);
}, 100);
const result = yield promise;
result.should.equals(DATA); //true
}).catch(err => console.error(err.stack));