MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / withTimeout

Function withTimeout

example/tests/window_message_test.js:52–58  ·  view source on GitHub ↗
(promise, label, ms = 10000)

Source from the content-addressed store, hash-verified

50 }
51
52 function withTimeout(promise, label, ms = 10000) {
53 let timer = null;
54 const timeout = new Promise((_, reject) => {
55 timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms);
56 });
57 return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
58 }
59
60 async function test(name, fn) {
61 results.total++;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected