@segment/analytics-next
Version:
Analytics Next (aka Analytics 2.0) is the latest version of Segment’s JavaScript SDK - enabling you to send your data to any tool without having to learn, test, or use a new API every time.
15 lines (13 loc) • 339 B
text/typescript
import { sleep } from '@segment/analytics-core'
export const waitForCondition = async (
condition: () => boolean,
timeout = 1000
): Promise<void> => {
const start = Date.now()
while (!condition()) {
if (Date.now() - start > timeout) {
throw new Error(`Timeout of ${timeout}ms exceeded!`)
}
await sleep(10)
}
}