co-on
co based event handling.
Last updated 6 years ago by hrsh7th .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install co-on 
SYNC missed versions from official npm registry.

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.

Current Tags

  • 0.0.5                                ...           latest (6 years ago)

5 Versions

  • 0.0.5                                ...           6 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |