Skip to content Skip to sidebar Skip to footer

Typescript Metronome

I'm trying to build a metronome with Typescript (and Angular 2). Thanks, to @Nitzan-Tomer (Typescript Loop with Delay), who helped me with the basics. Now I'm facing the issue, tha

Solution 1:

Here's a simple class to do it:

classMetronome {
    privateinterval: number;
    privatetimer: number;

    constructor(interval = 3000) {
        this.interval = interval;
    }

    start(): void {
        this.tick();
    }

    stop() {
        clearTimeout(this.timer);
    }

    setInterval(interval: number) {
        this.interval = interval;
    }

    privatetick() {
        // do something herethis.timer = setTimeout(this.tick.bind(this), this.interval);
    }
}

(code in playground)

Post a Comment for "Typescript Metronome"