Skip to content

Commit b988b53

Browse files
committed
section 4
1 parent 4e93b92 commit b988b53

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

code/.DS_Store

0 Bytes
Binary file not shown.

code/4.sync_async.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var fs = require('fs');
2+
3+
//Sync
4+
// 1출력, read 'data.txt' 작업 완료 후 data 출력
5+
console.log(1);
6+
var data = fs.readFileSync('data.txt', {encoding:'utf8'});
7+
console.log(data);
8+
9+
10+
//Async
11+
// 2출력, read 'data.txt' 작업을 백그라운드에게 맡긴 후 작업이 되는 시간에 4출력 이후 작업이 완료되면 콜백함수 실행(3출력 후 data 출력)
12+
console.log(2);
13+
fs.readFile('data.txt', {encoding:'utf8'}, function(err, data){ //'data.txt' 가 같은 폴더 내에 존재
14+
console.log(3);
15+
console.log(data);
16+
})
17+
console.log(4);

0 commit comments

Comments
 (0)