This function ensures that a provided promise is resolved within a specified time.
If the promise does not resolve within the specified time, an error is thrown.
import { timeout } from"@mrspartak/promises" import { api } from"./api"
// Can be used as a race condition const [error, user] = awaittimeout(api.getUser(), 1000) if (error) { // error can be either a timeout error or an error from the api }
Type Parameters
T
The type of the value that the input promise resolves to.
This function ensures that a provided promise is resolved within a specified time. If the promise does not resolve within the specified time, an error is thrown.
Example