View Source Bun.Supervisor (bun v2.0.0)
A pooled supervisor for managing bun processes.
Uses NimblePool to manage a pool of workers that can execute JavaScript code via bun. This allows for efficient reuse of bun processes without the overhead of spawning new processes for each call.
Usage
# Start the pool
{:ok, _pid} = Bun.Supervisor.start_link()
# Call a JavaScript module
{:ok, result} = Bun.Supervisor.call("myModule.js", ["arg1", "arg2"])
# Call with options
{:ok, result} = Bun.Supervisor.call("myModule.js", [], timeout: 10_000)
# Call and raise on error
result = Bun.Supervisor.call!("myModule.js", ["arg1"])
# Stop the pool
:ok = Bun.Supervisor.stop()
Summary
Functions
Calls a JavaScript module with the given arguments.
Calls a JavaScript module and raises on error.
Returns a child specification for use in a supervision tree.
Starts the pool of bun workers.
Stops the pool.
Functions
Calls a JavaScript module with the given arguments.
Arguments
module- Path to the JavaScript module to executeargs- List of arguments to pass to the module (default:[])opts- Options for the call
Options
:timeout- Maximum time to wait for the call in milliseconds (default:5000):pool- Name of the pool to use (default:Bun.Supervisor):cd- Working directory for the command (default:File.cwd!()):env- Environment variables for the command (default:%{})
Returns
{:ok, result}- The output from the JavaScript module{:error, reason}- If the call failed
Calls a JavaScript module and raises on error.
See call/3 for details on arguments and options.
Returns
The output from the JavaScript module.
Raises
Raises if the call fails.
Returns a child specification for use in a supervision tree.
Options
:pool_size- Number of workers in the pool (default:System.schedulers_online()):name- Name to register the pool (default:Bun.Supervisor)
Starts the pool of bun workers.
Options
:pool_size- Number of workers in the pool (default:System.schedulers_online()):name- Name to register the pool (default:Bun.Supervisor)
Stops the pool.