UNPKG

timing-functions

Version:

Set of universal utility functions around timing and scheduling in JavaScript

10 lines (8 loc) 244 B
import sleep from './sleep'; export default (timeout: number, promise: Promise<unknown>, message?: string) => Promise.race([ promise, sleep(timeout).then( () => new Error(message || `timed out after ${timeout}ms`) ), ]);