import Timeout = NodeJS.Timeout import { RequestTimeoutError } from '../errors' export class Timer { private readonly duration: number private timer: Timeout | null constructor (duration: number) { this.timer = null this.duration = duration } public run (): Promise { return new Promise((resolve, reject) => { this.timer = setTimeout(() => { reject(new RequestTimeoutError(this.duration)) }, this.duration) }) } public destroy (): void { if (!this.timer) { return } clearTimeout(this.timer) } }