https://github.com/hrsh7th/js-co-on
co based event emitter handling.
https://github.com/hrsh7th/js-co-on
Last synced: 3 days ago
JSON representation
co based event emitter handling.
- Host: GitHub
- URL: https://github.com/hrsh7th/js-co-on
- Owner: hrsh7th
- Created: 2014-05-15T13:18:57.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-07-02T05:28:50.000Z (over 11 years ago)
- Last Synced: 2025-09-11T14:41:44.989Z (29 days ago)
- Language: JavaScript
- Size: 273 KB
- Stars: 33
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
co-on
========[](https://travis-ci.org/hrsh7th/js-co-on)
co based event handling.
usage
--------
```js
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.');
});
``````js
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.
- return
- thunk or co-on object.#### ```yield e.on(...types)```
- args
- ...types
- event names.
- see usage.
- return
- EventEmitter#emit(type, ```...```);#### ```e.emitted(type)```
- args
- type
- event name.
- return
- whether event was already emitted (and buffer is empty).todo
--------
- error event handling.