gpipe
v1.0.1
Published
A generator module.
Downloads
1
Readme
gpipe
基于nodejs 0.11.14, ES6的generator. 方便编写顺序的异步代码.
gpipe.scc(generator[,callback]) 异步代码的串行运行
gpipe.mcc(generator[, callback]) 异步代码的并行运行
示例:
var fs = require('fs'),
pool = require('mysql').createPool({
host: "localhost",
port: 8080,
user: "root",
password: "",
database: "test",
connectionLimit: 10
}),
gpipe = require('gpipe');
gpipe.scc(function* (ctrl) {
var ro = yield fs.readFile('/test', { encoding:'utf8' }, ctrl);
var err = ro[0];
var data = ro[1];
if (err) {
throw err;
}
var wo = yield fs.writeFile('/new', data, { encoding:'utf8' }, ctrl);
var err = wo[0];
if (err) {
throw err;
}
var mo = gpipe.mcc(function* (ctrl) {
yield pool.query('SELECT * FROM employee', ctrl('employee'));
yield pool.query('SELECT * FROM deparment', ctrl('deparment'));
yield pool.query('SELECT * FROM order', ctrl('order'));
}, ctrl);
var employee = mo[0]['employee'];
var deparment = mo[0]['deparment'];
var order = mo[0]['order'];
}, function () {
console.log('complete');
});