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
| let x = "1"; | |
| runAsync(() => { | |
| x = "2"; | |
| // this will run second (or never) | |
| console.log(x); | |
| // this is pointless | |
| return x; | |
| }); | |
| // this will run first |
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
| let x = 0; | |
| x = setTimeout(() => { | |
| ++x; | |
| console.log(x); | |
| return x; | |
| }, 1000); | |
| console.log(x); |
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
| import {get, request} from "http"; | |
| import {readFile, writeFile} from "fs"; | |
| let host = "localhost"; | |
| let port = 8917; | |
| get({host, port}, response => { | |
| let body = ""; | |
| response.on("readable", () => { |
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
| import {get, request} from "http"; | |
| import {readFile, writeFile} from "fs"; | |
| let host = "localhost"; | |
| let port = 8917; | |
| let body = ""; | |
| get({host, port}, completeRequest(finalCb)); | |
| function finalCb(err, result) { |
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
| function runSync(cb) { | |
| cb(); | |
| } | |
| let x = 0; | |
| runSync(() => ++x); | |
| console.log(x); |
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
| let x = 0; | |
| Array.of(1, 2, 3).forEach(() => ++x); | |
| console.log(x); |
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
| function isItAsync(file, cb) { | |
| if (!file) { | |
| cb("no file"); | |
| } | |
| fs.readFile(file, cb); | |
| } |
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
| import {readFile} from "fs"; | |
| let file; | |
| function isItAsync(file, cb) { | |
| if (!file) { | |
| return cb("no file"); | |
| } | |
| readFile(file, cb); | |
| } |
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
| import request from "request-promise"; | |
| import {readFile, writeFile} from "mz/fs"; | |
| let uri = "http://localhost:8917"; | |
| request.get({uri}) | |
| .then(body => writeFile(__dirname + "/foo", body)) | |
| .then(() => readFile(__dirname + "/foo")) | |
| .then(contents => writeFile(__dirname + "/bar", contents.toString().split("").reverse().join(""))) | |
| .then(() => request({uri, method: "POST"})) |
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
| import request from "request-promise"; | |
| import {readFile, writeFile} from "mz/fs"; | |
| import co from "co"; | |
| let uri = "http://localhost:8917"; | |
| co(function* () { | |
| let body = yield request.get({uri}); | |
| yield writeFile(__dirname + "/foo", body); | |
| let contents = yield readFile(__dirname + "/foo"); |