UNPKG

ipfs-interop

Version:

Interoperability Tests for IPFS

25 lines (20 loc) 463 B
import delay from 'delay' /** * Wait for a condition to become true * * @param {() => boolean} predicate * @param {number} ttl * @param {number} checkInterval */ export async function waitFor (predicate, ttl = 10e3, checkInterval = 50) { const timeout = Date.now() + ttl while (true) { if (predicate()) { return } await delay(checkInterval) if (Date.now() > timeout) { throw new Error('waitFor time expired') } } }