* 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)
| 103 | * @throws {Error} If the function took to long. |
| 104 | */ |
| 105 | function 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 | |
| 126 | const bridgeScript = compileScript( |
| 127 | `${__dirname}/bridge.js`, |
no outgoing calls
no test coverage detected
searching dependent graphs…