npm.io
0.0.6 • Published 12 years ago

cooperator

Licence
—
Version
0.0.6
Deps
2
Vulns
0
Weekly
0

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 it
  • co.on('data', cb(data)) - An event emitted when the generator yields a value that can't be thunkifyered
  • co.on('done', cb(res)) - An event emitted when the generator returns
  • co.on('error', cb(err)) - An event emitted when the generator throws an error
  • co.pullStream - A pull-stream for the data