通过回调函数异步并发问题_2021-03-02

//多个异步请求,如何同时获取最终结果
let fs = require('fs');
const { createBrotliCompress } = require('zlib');
let school = {}

let index = 0

function after(times, callback){
    return function(){
        if(--times == 0){
            callback()
        }
    }
}

let cb = after(2, function(){
    console.log(school)
})

fs.readFile('./name.txt', 'utf8', function(err, data){
    school.name = data;
    cb();
})

fs.readFile('./age.txt', 'utf8', function(err, data){
    school.age = data
    cb()
})


你可能感兴趣的:(通过回调函数异步并发问题_2021-03-02)