SOURCE

function asyncPromise() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            const res = {};
            // const res = null;
            if (res) {
                return resolve(res);
            } else {
                return reject({ msg: "报错" })
                // throw new Error("报错")
            }
        }, 1000)
    })
}

class Sensors {
    constructor() {
        this.pedding = false;
        this.tracks = [];
    }
    track(name, params) {
        this.tracks.push({
            name,
            params
        })
        if (this.pedding) {
            return;
        }
        this.pedding = true;
        asyncPromise().then(res => {
            console.log(this.tracks);
            this.tracks.forEach(item => {
                console.log(item)
            })
        }).catch(error => {
            console.log(error)
        }).finally(() => {
            this.tracks = [];
            this.pending = false;
        });

    }
}

const sensor = new Sensors();

sensor.track("a", 1);
sensor.track("b", 2);
sensor.track("c", 3);

console 命令行工具 X clear

                    
>
console