Update app.mjs
Browse files
app.mjs
CHANGED
|
@@ -24,6 +24,7 @@ if (!isMainThread) {
|
|
| 24 |
parentPort.postMessage({ error: format(error) })
|
| 25 |
}
|
| 26 |
})
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
const isNumber = (v) => typeof v === 'number' && !isNaN(v)
|
|
@@ -65,36 +66,35 @@ const getServerStats = () => {
|
|
| 65 |
return stats
|
| 66 |
}
|
| 67 |
|
| 68 |
-
const runBrowserScript = (code) =>
|
| 69 |
-
new
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
})
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
})
|
| 89 |
-
worker.on('error', (err) => {
|
| 90 |
-
cleanup()
|
| 91 |
-
reject(err)
|
| 92 |
-
})
|
| 93 |
-
worker.on('exit', (exitCode) => {
|
| 94 |
-
clearTimeout(timer)
|
| 95 |
-
exitCode !== 0 && reject(new Error(`Worker exited with code ${exitCode}`))
|
| 96 |
-
})
|
| 97 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
const app = new Hono()
|
| 100 |
|
|
|
|
| 24 |
parentPort.postMessage({ error: format(error) })
|
| 25 |
}
|
| 26 |
})
|
| 27 |
+
return true
|
| 28 |
}
|
| 29 |
|
| 30 |
const isNumber = (v) => typeof v === 'number' && !isNaN(v)
|
|
|
|
| 66 |
return stats
|
| 67 |
}
|
| 68 |
|
| 69 |
+
const runBrowserScript = (code) => new Promise((resolve, reject) => {
|
| 70 |
+
const worker = new Worker(new URL(import.meta.url), {
|
| 71 |
+
resourceLimits: { maxOldGenerationSizeMb: 512 }
|
| 72 |
+
})
|
|
|
|
| 73 |
|
| 74 |
+
const timer = setTimeout(() => {
|
| 75 |
+
worker.terminate()
|
| 76 |
+
reject(new Error('Execution timeout'))
|
| 77 |
+
}, TIMEOUT_MS)
|
| 78 |
|
| 79 |
+
const cleanup = () => {
|
| 80 |
+
clearTimeout(timer)
|
| 81 |
+
worker.terminate()
|
| 82 |
+
}
|
| 83 |
|
| 84 |
+
worker.postMessage(code)
|
| 85 |
+
worker.on('message', ({ result, error }) => {
|
| 86 |
+
cleanup()
|
| 87 |
+
error ? reject(new Error(error)) : resolve(format(result))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
})
|
| 89 |
+
worker.on('error', (err) => {
|
| 90 |
+
cleanup()
|
| 91 |
+
reject(err)
|
| 92 |
+
})
|
| 93 |
+
worker.on('exit', (exitCode) => {
|
| 94 |
+
clearTimeout(timer)
|
| 95 |
+
exitCode !== 0 && reject(new Error(`Worker exited with code ${exitCode}`))
|
| 96 |
+
})
|
| 97 |
+
})
|
| 98 |
|
| 99 |
const app = new Hono()
|
| 100 |
|