Skip to content

Commit 0ffbe90

Browse files
committed
promiseAll
1 parent 7822bf2 commit 0ffbe90

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// after 在 ... 之后
2+
// 我希望我调用某个函数 3次之后 再去执行
3+
4+
function after(time,say){
5+
return function () {
6+
if((--time) == 0) {
7+
say();
8+
}
9+
}
10+
}
11+
12+
let nweSay = after(3,function say() {
13+
// 保存一个变量 到after的内部
14+
console.log('say');
15+
})
16+
17+
nweSay();
18+
nweSay();
19+
nweSay();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs =require('fs')
2+
// fs 是一个node 中 file System 有文件的读写操作
3+
// node中异步方法都有回调 并发 同时去读取文件 读取完毕的时机不一样
4+
// 并发操作 就是两个操作互不影响
5+
6+
function after (times,say){
7+
let renderObj ={};
8+
return function (key,value) {
9+
renderObj[key] = value;
10+
if(--times == 0){
11+
say(renderObj);
12+
}
13+
}
14+
}
15+
16+
let out = after(2,(renderObj)=>{
17+
console.log(renderObj);
18+
})
19+
20+
fs.readFile('文件路径','utf8',function (err,data){
21+
out('name',data);
22+
})
23+
24+
fs.readFile('文件路径','utf8',function(err,data){
25+
out("name",data);
26+
})

0 commit comments

Comments
 (0)