useage: node with optional --harmony_destructuring
var fs = require('fs') var request = require('request') var lightco = require('lightco') lightco.run(function* ($) { var [error, data] = yield fs.readFile('index.js', 'utf8', $) if (error) throw error console.log(data) var [error, response, body] = yield request('http://www.baidu.com', $) if (error) throw error console.log(response.statusCode) var [error, data] = yield query(true) if (error) throw error console.log(data) })
when onRejected was invoked, the first argument error must be a Error
when onFulfilled was invoked, the first argument must be a null, the second argument must be a data
var immediatelyInvoke = function(cb) { cb('hi!') } // this will be generate a error (Generator is already running)
MIT