MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / getWorker

Function getWorker

docs/components/runtime.js:22–35  ·  view source on GitHub ↗
(onPhase)

Source from the content-addressed store, hash-verified

20
21// `onPhase` only matters for the first (cold) call: 'runtime' (downloading the ESM) then 'worker' (spawn + wasm fetch/instantiate).
22function getWorker(onPhase) {
23 if (workerPromise) return workerPromise
24 workerPromise = (async () => {
25 onPhase?.('runtime')
26 // webpackIgnore keeps Next from bundling the cross-origin ESM; it loads in the browser at runtime.
27 const { createWorker } = await import(/* webpackIgnore: true */ RUNTIME_URL)
28 onPhase?.('worker')
29 const worker = await createWorker({ wasmUrl: WASM_URL, integrity: true })
30 worker.onOutput((chunk) => { if (activeSink) activeSink(chunk) })
31 workerReady = true
32 return worker
33 })()
34 return workerPromise
35}
36
37/* Run `src`, streaming each raw stdout chunk to `onChunk`. `onPhase` reports 'runtime'/'worker' (cold start only) then 'running'. Resolves with the error text (empty on success) and elapsed ms. */
38export async function run(src, onChunk, onPhase) {

Callers 1

execFunction · 0.85

Calls 2

createWorkerFunction · 0.85
onOutputMethod · 0.80

Tested by

no test coverage detected