Skip to content

Instantly share code, notes, and snippets.

@nashibao
Created January 13, 2014 04:35
Show Gist options
  • Save nashibao/8394774 to your computer and use it in GitHub Desktop.
Save nashibao/8394774 to your computer and use it in GitHub Desktop.
co-gate sample script.
// require co
var co = require('co')
, Gate = require('co-gate')
, fs = require('fs');
co(function *(){
// create gate
var gate = new Gate()
, val = undefined;
// just call normal apis with gate.in() as callback
fs.readFile("test/test1.txt", "utf-8", gate.in());
fs.readFile("test/test2.txt", "utf-8", gate.in());
try{
// yielded
val = yield gate.out();
}catch(e){
console.log(e);
}
assert.equal(val[0], 'test1');
assert.equal(val[1], 'test2');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment