UNPKG

homebridge-broadlink-rm-pro

Version:

Broadlink RM plugin (including the mini and pro) for homebridge with AC Pro and TV features

34 lines (23 loc) 690 B
const { TIMEOUT_CANCELLATION } = require('./errors') function delayForDuration(duration) { let timerID, endTimer, timer; const promiseFunc = function (resolve, reject) { endTimer = reject; timerID = setTimeout(() => { resolve('Timeout Complete'); this.isCancelled = true; }, duration * 1000); } class Timer extends Promise { cancel () { if (this.isCancelled) {return;} clearTimeout(timerID); this.isCancelled = true; endTimer(new Error(TIMEOUT_CANCELLATION)); } } timer = new Timer(promiseFunc); timer.isCancelled = false; return timer; } module.exports = delayForDuration;