-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathasync_example.js
More file actions
28 lines (28 loc) · 848 Bytes
/
async_example.js
File metadata and controls
28 lines (28 loc) · 848 Bytes
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
var fs = require('fs');
var firstFileRead = false;
var t1 = Date.now();
var t2;
//simulating two long-running asynchronous file I/O operations
fs.readFile('Taiko.txt', function (error, fileContents) {
setTimeout(function () {
console.log(fileContents.toString());
if (!firstFileRead) {
firstFileRead = true;
} else {
t2 = Date.now();
console.log((t2 - t1) + ' milliseconds elapsed');
}
}, 5000);
});
//console.log('\n\n********** this will be logged after the readFile call is made, but before the file contents have been logged **********\n\n');
fs.readFile('Gunter_Grass.txt', function (error, fileContents) {
setTimeout(function () {
console.log(fileContents.toString());
if (!firstFileRead) {
firstFileRead = true;
} else {
t2 = Date.now();
console.log((t2 - t1) + ' milliseconds elapsed');
}
}, 5000);
});