js-workers
Workers is the common library for multi-threading in MatrixAI's JavaScript/TypeScript applications. It uses the WebWorker API. Later for Mobile OSes, there are multiple potential solutions here using NativeScript or React Native.
Beware that when transferring buffers between the main thread and worker threads, make sure to follow this architecture.
βββββββββββββββββββββββββ
β Main Thread β
β β
β βββββββββββββ β
β βNode Bufferβ β
β βββββββ¬ββββββ β ββββββββββββββββββββββββββ
β β β β β
β Slice β Copy β β Worker Thread β
β β β β β
β ββββββββββΌβββββββββ β Transfer β ββββββββββββββββββββ β
β βInput ArrayBufferββββΌβββββββββββΌβββΊ β β
β βββββββββββββββββββ β β βββββββββββ¬βββββββββ β
β β β β β
β β β Compute β β
β β β β β
β βββββββββββββββββββ β β βββββββββββΌβββββββββ β
β β ββββΌβββββββββββΌβββ€Output ArrayBufferβ β
β βββββββββββββββββββ β Transfer β ββββββββββββββββββββ β
β β β β
β β β β
βββββββββββββββββββββββββ ββββββββββββββββββββββββββ
Installation
npm install --save @matrixai/workers
Development
Run nix-shell
, and once you're inside, you can use:
npm install
npm run build
npm run ts-node
npm run test
npm run lint
npm run lintfix
Docs Generation
npm run docs
See the docs at: https://matrixai.github.io/js-workers/
Publishing
npm version patch
npm run build
npm publish --access public
git push
git push --tags