forked from codedinc/eventloopclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslow.js
30 lines (23 loc) · 722 Bytes
/
slow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var http = require('http');
// NOTE: We're now using Node.js builtin event loop. NOT the loop we built in loop.js
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
if (req.url == "/slow") {
var objects = [];
var i=0;
function compute() {
// for (var j=0; j < 10000; j++, i++) { // compute faster, but make loop slow
objects.push(new Object()); // pretend we're computing something here
// };
if (i < 10000000) {
i++;
process.nextTick(compute);
} else {
res.end("slow request done");
}
}
compute();
} else {
res.end("fast request done");
}
}).listen(3000);