Created
November 25, 2011 13:29
-
-
Save KOBA789/1393528 to your computer and use it in GitHub Desktop.
async-without-indent
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
| some |
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
| data |
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
| var fs = require('fs'); | |
| function readFile (filename) { | |
| return function () { | |
| fs.readFile(filename, 'utf8', arguments.callee.next); | |
| } | |
| } | |
| function getData() { | |
| return function (err, data) { | |
| if (err) throw err; | |
| if (arguments.callee.next) { | |
| arguments.callee.next(data); | |
| } | |
| } | |
| } | |
| function putStrLn () { | |
| return function (data) { | |
| console.log(data); | |
| if (arguments.callee.next) { | |
| arguments.callee.next(); | |
| } | |
| } | |
| } | |
| function wait (time) { | |
| return function () { | |
| setTimeout(arguments.callee.next, time); | |
| } | |
| } | |
| function param (val) { | |
| return function () { | |
| arguments.callee.next(val); | |
| } | |
| } | |
| var main; | |
| main = new param('hello'); | |
| main.next = new putStrLn; | |
| main.next.next = new wait(1000); | |
| main.next.next.next = new param('world'); | |
| main.next.next.next.next = new putStrLn; | |
| main.next.next.next.next.next = new readFile('a.txt'); | |
| main.next.next.next.next.next.next = new getData; | |
| main.next.next.next.next.next.next.next = new putStrLn; | |
| main.next.next.next.next.next.next.next.next = new readFile('b.txt'); | |
| main.next.next.next.next.next.next.next.next.next = new getData; | |
| main.next.next.next.next.next.next.next.next.next.next = new putStrLn; | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment