co-on
v0.0.5
Published
co based event handling.
Downloads
3
Readme
co-on
co based event handling.
usage
var co = require('co');
var on = require('co-on');
co(function*() {
var db = require('db');
db.connect('localhost/example');
yield on(db, 'connect');
console.log('connect success.');
});
var co = require('co');
var on = require('co-on');
var fs = require('fs');
co(function*() {
var stream = fs.createReadStream('sample.txt').resume();
var e = on(stream)
var data = '';
while (!e.emitted('end')) {
var chunk = yield e.on('data', 'end');
if (chunk) {
data += chunk;
}
}
console.log(data);
});
api
var e = on(emitter, [...types]);
- args
- emitter
- EventEmitter instance.
- ...types
- event names.
- emitter
- return
- thunk or co-on object.
yield e.on(...types)
- args
- ...types
- event names.
- see usage.
- event names.
- ...types
- return
- EventEmitter#emit(type,
...
);
- EventEmitter#emit(type,
e.emitted(type)
- args
- type
- event name.
- type
- return
- whether event was already emitted (and buffer is empty).
todo
- error event handling.