Fork
Function: Fork()
Fork(
callback,parentCallback?,output?):Promise<void>
Defined in: packages/workout/src/fork.ts:77
Launch a forked process to run the callback Automatically forwards all logging and progress events between parent and child processes
Parameters
callback
() => void | Promise<void>
Function to run in the forked child process
parentCallback?
() => void | Promise<void>
Optional function to run in the parent process while child executes
output?
Optional WorkerOutput instance for logging (defaults to global instance)
Returns
Promise<void>
Promise that resolves when the child process exits with code 0, rejects otherwise
Example
import { Fork } from "@webda/workout";
await Fork(async () => {
// This code runs in the forked process
useLog("Hello from the forked process");
useWorkerOutput().startActivity("Test");
await new Promise(resolve => setTimeout(resolve, 2000));
useWorkerOutput().stopActivity("Test");
}, () => {
// This code runs in the parent process
useLog("Hello from the parent process");
});