UNPKG

@koush/ring-client-api

Version:

Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting

31 lines (24 loc) 567 B
export class TargetValueTimer<T> { private timeout: number | undefined private targetValue: T | undefined setTarget(value: T, duration: number) { this.reset() this.targetValue = value this.timeout = setTimeout(() => { this.reset() }, duration) as any as number } hasTarget() { return this.timeout !== undefined } getTarget() { return this.targetValue as T } reset() { if (this.timeout !== undefined) { clearTimeout(this.timeout) } this.targetValue = undefined this.timeout = undefined } }