co-on

0.0.5 • Public • Published

co-on

Build Status

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.
  • 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.

/co-on/

    Package Sidebar

    Install

    npm i co-on

    Weekly Downloads

    1

    Version

    0.0.5

    License

    MIT

    Last publish

    Collaborators

    • hrsh7th