interface
WorkerOptions
interface WorkerOptions
Bun's Web Worker constructor supports some extra options on top of the API browsers have.
- argv?: any[]
List of arguments to stringify and append to
Bun.argv/process.argvin the worker. The values are available on the globalBun.argvas if they were passed as CLI options to the script. - env?: Record<string, string> | typeof SHARE_ENV
If set, the initial value of
process.envinside the Worker thread. Passworker.SHARE_ENVfromnode:worker_threadsto share environment variables between the parent and worker threads; changes to one thread'sprocess.envthen affect the other thread as well. Default:process.env. - name?: string
An identifying name for the worker's
DedicatedWorkerGlobalScope, mainly useful for debugging. - preload?: string | string[]
An array of module specifiers to preload in the worker.
These modules load before the worker's entry point is executed.
Equivalent to passing the
--preloadCLI argument, but only for this Worker. - ref?: boolean
When
true, the worker keeps the parent thread alive until the worker is terminated orunref'd. Whenfalse, it does not. - smol?: boolean
Use less memory, but make the worker slower.
Internally, this sets the heap size configuration in JavaScriptCore to be the small heap instead of the large heap.