UNPKG

teletype-client-modified

Version:

I have modified the library developed by Atom to make it compatible with non-browser facility. I am using it only for experimentation purposes. I will remove this package post my experiment and raise a PR at Atom to finally merge this package so that this

21 lines (18 loc) 527 B
module.exports = function condition (fn) { const timeoutError = new Error('Condition timed out: ' + fn.toString()) Error.captureStackTrace(timeoutError, condition) return new Promise((resolve, reject) => { const intervalId = global.setInterval(() => { if (fn()) { global.clearTimeout(timeout) global.clearInterval(intervalId) resolve() } }, 5) const timeout = global.setTimeout(() => { global.clearInterval(intervalId) reject(timeoutError) }, 500) }) }