Skip to content

Commit

Permalink
Merge branch 'parallel-creative' into retriever-backport
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Aug 25, 2024
2 parents 827e4c8 + 6f73991 commit ffdac38
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,28 @@ export function cartesian(a: number[][]): number[][] {

export function hash(toHash: string) {
return crypto.createHash("md5").update(toHash).digest("hex");

Check warning on line 56 in src/misc.ts

View check run for this annotation

Codecov / codecov/patch

src/misc.ts#L56

Added line #L56 was not covered by tests
}

export class TimeoutError extends Error {
constructor(message: string) {
super(message);
this.name = "TimeoutError";

Check warning on line 62 in src/misc.ts

View check run for this annotation

Codecov / codecov/patch

src/misc.ts#L61-L62

Added lines #L61 - L62 were not covered by tests
}
}

// Do not use on the same promise multiple times
export function timeoutPromise<T>(promise: Promise<T>, timeout: number): Promise<T> {
let reject = (_: any) => {};
let resolve = (_: T) => {};
const cancel = setTimeout(() => {
reject(new TimeoutError(`Promise exceeded timeout of ${timeout/1000} seconds.`));

Check warning on line 71 in src/misc.ts

View check run for this annotation

Codecov / codecov/patch

src/misc.ts#L68-L71

Added lines #L68 - L71 were not covered by tests
}, timeout);
promise
.then(result => resolve(result))
.catch(error => reject(error))
.finally(() => clearTimeout(cancel));
return new Promise<T>((newResolve, newReject) => {
resolve = newResolve;
reject = newReject;

Check warning on line 79 in src/misc.ts

View check run for this annotation

Codecov / codecov/patch

src/misc.ts#L73-L79

Added lines #L73 - L79 were not covered by tests
});
}

0 comments on commit ffdac38

Please sign in to comment.