未古其人

目录

避免同一请求的重复调用

let inLoading = false, promise = null;

function getData() {
    if (!inLoading) {
        inLoading = true
        promise = new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve({a:Date.now()});
            }, 1000);
        });
    }
    return promise;
};

module.exports = {
    execute: async () => {
        let data1 = await getData();
        let data2 = await getData();
        console.log(data1);
        console.log(data2);
    }
}