Themodulealsoimplementssupportforboundworkers.Bindingaworkermeansthat,basedoncertainparameters,thesametaskwillalwaysbeexecutedbythesameworker.Thewayboundworkersworkisbyusingthereturnedstringofthe`computeWorkerKey` method. If the string was used before for a task, the call will be queued to the related worker that processed the task earlier; if not, it will be executed by the first available worker, then sticked to the worker that executed it; so the next time it will be processed by the same worker. If you have no preference on the worker executing the task, but you have defined a `computeWorkerKey` method because you want _some_ of the tasks to be sticked, you can return `null`fromit.
Node10shippedwith[worker-threads](https://nodejs.org/api/worker_threads.html), a "threading API" that uses SharedArrayBuffers to communicate between the main process and its child threads. This experimental Node feature can significantly improve the communication time between parent and child processes in `jest-worker`.
Since`worker_threads` are considered experimental in Node, you have to opt-in to this behavior by passing `enableWorkerThreads: true` when instantiating the worker. While the feature was unflagged in Node 11.7.0, you'll need to run the Node process with the `--experimental-worker`flagforNode10.
Listofmethodnamesthatcanbecalledonthechildprocessesfromtheparentprocess.Youcannotexposeanymethodnamedlikeapublic`Worker` method, or starting with `_`.Ifyouusemethodauto-discovery,thenthesemethodswillnotbeexposed,eveniftheyexist.
Allowcustomizingalloptionspassedto`childProcess.fork`. By default, some values are set (`cwd`, `env` and `execArgv`),butyoucanoverridethemandcustomizetherest.Foralistofvalidvalues,check[theNodedocumentation](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options).
EverytimeamethodexposedviatheAPIiscalled,`computeWorkerKey` is also called in order to bound the call to a worker. This is useful for workers that are able to cache the result or part of it. You bound calls to a worker by making `computeWorkerKey` return the same identifier for all different calls. If you do not want to bind the call to any worker, return `null`.
Returnsa`ReadableStream` where the standard output of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
####`getStderr(): Readable`
Returnsa`ReadableStream` where the standard error of all workers is piped. Note that the `silent` option of the child workers must be set to `true` to make it work. This is the default set by `jest-worker`, but keep it in mind when overriding options through `forkOptions`.
ReturnsaPromisethatresolveswith`{ forceExited: boolean }` once all workers are dead. If `forceExited` is `true`,atleastoneoftheworkersdidnotexitgracefully,whichlikelyhappenedbecauseitexecutedaleakytaskthatlefthandlesopen.Thisshouldbeavoided,forceexitingworkersisalastresorttopreventcreatinglotsoforphans.
**Note:**
`await`ing the `end()` Promise immediately after the workers are no longer needed before proceeding to do other useful things in your program may not be a good idea. If workers have to be force exited, `jest-worker`maygothroughmultiplestagesofforceexiting(e.g.SIGTERM,laterSIGKILL)andgivetheworkeroverallaround1secondtimetoexitonitsown.Duringthistime,yourprogramwillwait,eventhoughitmaynotbenecessarythatallworkersaredeadbeforecontinuingexecution.