cooperator
v0.0.6
Published
Like co but lets you also output data
Downloads
1
Readme
Cooperator
Usage
var cooperator = require('cooperator')
var sleep = require('co-sleep')
var co = cooperator(function*() {
yield 'foo'
yield sleep(2000)
yield 'bar'
yield sleep(2000)
yield 'baz'
}).on('data', function(data) {
console.log('data', data)
}).on('error', function(err) {
console.error('error', err.stack)
}).on('done', function(res) {
console.log('done', res)
}).start()
// yields
// data foo
// data bar
// data baz
// done undefined
API
co = cooperator(gen)
- Creates a cooperator from gen (can be a generator or a generator function)co.start()
- Start itco.on('data', cb(data))
- An event emitted when the generator yields a value that can't be thunkifyeredco.on('done', cb(res))
- An event emitted when the generator returnsco.on('error', cb(err))
- An event emitted when the generator throws an errorco.pullStream
- A pull-stream for the data