Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created November 13, 2011 17:03
Show Gist options
  • Save isaacs/1362338 to your computer and use it in GitHub Desktop.
Save isaacs/1362338 to your computer and use it in GitHub Desktop.
var start = Date.now()
http = require("http")
console.error("%d scheduling nextTick", Date.now() - start)
process.nextTick(function interval(){
process.nextTick(interval)
process.stderr.write(".")
})
console.error("%d nextTick created", Date.now() - start)
console.error("%d creating server", Date.now() - start)
http.createServer(function (req, res) {
console.error("\n%d SERVER: got request", Date.now() - start)
res.writeHead(200)
res.end("ok\n")
}).listen(1337)
console.error("%d server created", Date.now() - start)
console.error("%d scheduling request", Date.now() - start)
setTimeout(function () {
console.error("\n%d CLIENT: making request", Date.now() - start)
http.get({ host: "localhost"
, port: 1337
, path: "/" }).on("response", function (res) {
console.error("\n%d CLIENT: got response", Date.now() - start)
res.pipe(process.stdout)
res.on("end", function () {
console.error("\n%d CLIENT: request ended", Date.now() - start)
process.exit(0)
})
})
}, 10)
console.error("%d first tick over", Date.now() - start)
@isaacs
Copy link
Author

isaacs commented Nov 13, 2011

Output:

$ node recursive-nexttick.js 
12 scheduling nextTick
16 nextTick created
16 creating server
17 server created
17 scheduling request
17 first tick over
....................................................................................
....................................................................................
....................................................................................
.......
27 CLIENT: making request
..................
41 SERVER: got request
..
42 CLIENT: got response
ok

42 CLIENT: request ended

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment