Wie stoppe ich die asynchrone Funktion in JavaScript?

Ich habe einige asynchrone Probleme. Ich arbeite an einemECMAScript 6 Objekt. Es ist ein Timer und ich möchte in der Lage sein, während des Countdowns neu zu starten.

Hier ist meine Arbeit:

export class Timer {
    constructor(sec){
        this.sec = sec;
        this.count = sec;
        this.running = false;
    }

    start() {
        this.running = true;
        this._run();
    }

    _run(){
        if(this.running){
            setTimeout(()=>{
                this.count --;
                console.log(this.count);
                if(this.count<0){
                    this.running = false;
                }
                this._run();
            }, 1000);
        }
    }

    restart(){
        this.running = false;
        /*
            Wait until _run() is done then :
        */
        this.count = this.sec;
        this.start();
    }
}

In demrestart() Funktion, wie kann ich wissen, wann_run() hat aufgehört zu laufen?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage