MCPcopy
hub / github.com/patriksimek/vm2 / doWithTimeout

Function doWithTimeout

lib/vm.js:105–124  ·  view source on GitHub ↗

* Run a function with a specific timeout. * * @private * @param {runWithTimeout} fn - Function to run with the specific timeout. * @param {number} timeout - The amount of time to give the function to finish. * @return {*} The value returned by the function. * @throws {Error} If the function to

(fn, timeout)

Source from the content-addressed store, hash-verified

103 * @throws {Error} If the function took to long.
104 */
105function doWithTimeout(fn, timeout) {
106 if (!cacheTimeoutContext) {
107 cacheTimeoutContext = createContext();
108 cacheTimeoutScript = new Script('fn()', {
109 __proto__: null,
110 filename: 'timeout_bridge.js',
111 displayErrors: false,
112 });
113 }
114 cacheTimeoutContext.fn = fn;
115 try {
116 return cacheTimeoutScript.runInContext(cacheTimeoutContext, {
117 __proto__: null,
118 displayErrors: false,
119 timeout,
120 });
121 } finally {
122 cacheTimeoutContext.fn = null;
123 }
124}
125
126const bridgeScript = compileScript(
127 `${__dirname}/bridge.js`,

Callers 1

runMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…