MCPcopy Create free account
hub / github.com/andywer/threads.js / withTimeout

Function withTimeout

src/master/spawn.ts:46–59  ·  view source on GitHub ↗
(promise: Promise<T>, timeoutInMs: number, errorMessage: string)

Source from the content-addressed store, hash-verified

44 : 10000
45
46async function withTimeout<T>(promise: Promise<T>, timeoutInMs: number, errorMessage: string): Promise<T> {
47 let timeoutHandle: any
48
49 const timeout = new Promise<never>((resolve, reject) => {
50 timeoutHandle = setTimeout(() => reject(Error(errorMessage)), timeoutInMs)
51 })
52 const result = await Promise.race([
53 promise,
54 timeout
55 ])
56
57 clearTimeout(timeoutHandle)
58 return result
59}
60
61function receiveInitMessage(worker: WorkerType): Promise<WorkerInitMessage> {
62 return new Promise((resolve, reject) => {

Callers 1

spawnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected