-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
73 lines (65 loc) · 2.7 KB
/
app.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var fs = require('fs');
var firstFileRead = false;
var t1 = 0;
var t2 = 0;
var fileContents = null;
t1 = Date.now();
// simulating two long-running synchronous file I/O operations
// function readFiles() {
// setTimeout(function () {
// fileContents = fs.readFileSync('Taiko.txt', 'utf8');
// console.log(fileContents);
// setTimeout(function () {
// fileContents = fs.readFileSync('Gunter_Grass.txt', 'utf8');
// console.log(fileContents);
// t2 = Date.now();
// console.log((t2 - t1) + ' milliseconds elapsed');
// }, 5000);
// }, 5000);
// }
// readFiles();
// two synchronous file I/O operations
// var fileContents = fs.readFileSync('Taiko.txt', 'utf8');
// console.log(fileContents);
// console.log('\n\n********** you will not see this until the file contents have been logged **********\n\n');
// fileContents = fs.readFileSync('Gunter_Grass.txt', 'utf8');
// console.log(fileContents);
// console.log('\n\n********** you will not see this until the next file contents have been logged **********\n\n');
// t2 = Date.now();
// console.log((t2 - t1) + ' milliseconds elapsed');
// two asynchronous file I/O operations
// fs.readFile('Taiko.txt', function (error, fileContents) {
// // console.log(fileContents.toString());
// });
// 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) {
// // console.log(fileContents.toString());
// });
// console.log('\n\n********** this also will be logged after the readFile call is made, but before the file contents have been logged **********\n\n');
// 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(fileContents.toString());
// });
// 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);
// // console.log(fileContents.toString());
// });
// console.log('\n\n********** this also will be logged after the readFile call is made, but before the file contents have been logged **********\n\n');