Skip to content

Instantly share code, notes, and snippets.

View connorads's full-sized avatar

Connor Adams connorads

View GitHub Profile
@connorads
connorads / promiseWithTimeout.ts
Created September 25, 2020 10:47
Wrapping a promise with a timeout in Typescript (adapted from https://bit.ly/3j1fmli)
export class TimeoutError extends Error {
constructor(message: string) {
super(message);
this.name = "TimeoutError";
}
}
export const promiseWithTimeout = <T>({
ms,
promise,