UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

127 lines (60 loc) 2.42 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [rc-js-util](./rc-js-util.md) &gt; [IWorkerPool](./rc-js-util.iworkerpool.md) ## IWorkerPool interface A shared pool of web workers to run jobs off the main thread. **Signature:** ```typescript export interface IWorkerPool extends IManagedObject, IPointer ``` **Extends:** [IManagedObject](./rc-js-util.imanagedobject.md)<!-- -->, [IPointer](./rc-js-util.ipointer.md) ## Remarks If you know the number of threads you need, use `-sPTHREAD_POOL_SIZE=` to allocate them up front. ## Methods <table><thead><tr><th> Method </th><th> Description </th></tr></thead> <tbody><tr><td> [addJob(jobPtr)](./rc-js-util.iworkerpool.addjob.md) </td><td> Transfer unique ownership of the job to the pool. If the pool is running, the job should eventually be run. </td></tr> <tr><td> [areWorkersSynced()](./rc-js-util.iworkerpool.areworkerssynced.md) </td><td> Becomes true once only "valid" jobs are running i.e. all the invalid jobs are gone - use in combination with [IWorkerPool.invalidateBatch()](./rc-js-util.iworkerpool.invalidatebatch.md)<!-- -->. </td></tr> <tr><td> [hasPendingWork()](./rc-js-util.iworkerpool.haspendingwork.md) </td><td> True if there is any job which has yet to be run. The answer is guaranteed correct on the producer thread. </td></tr> <tr><td> [invalidateBatch()](./rc-js-util.iworkerpool.invalidatebatch.md) </td><td> Cancel any outstanding jobs, does not kill the current job (which must complete first). </td></tr> <tr><td> [isBatchDone()](./rc-js-util.iworkerpool.isbatchdone.md) </td><td> This can be polled using [promisePoll()](./rc-js-util.promisepoll.md)<!-- -->.; </td></tr> <tr><td> [isRunning()](./rc-js-util.iworkerpool.isrunning.md) </td><td> </td></tr> <tr><td> [setBatchEnd()](./rc-js-util.iworkerpool.setbatchend.md) </td><td> After adding jobs, you can mark the last job on each worker to track when they have all be completed using [IWorkerPool.isBatchDone()](./rc-js-util.iworkerpool.isbatchdone.md)<!-- -->. </td></tr> <tr><td> [start()](./rc-js-util.iworkerpool.start.md) </td><td> </td></tr> <tr><td> [stop()](./rc-js-util.iworkerpool.stop.md) </td><td> </td></tr> </tbody></table>