Created
January 13, 2014 04:35
-
-
Save nashibao/8394774 to your computer and use it in GitHub Desktop.
co-gate sample script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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