harmony-worker

1.0.1 • Public • Published

harmony-worker

Make web worker more easy to use.

Installation

Download and include the 'index.js' in your code. If you are in nodejs or otherwise using npm, run:

npm install harmony-worker

Example

import harmonyWorker from 'harmony-worker'

// If there are transferable data.
async function doSomething1(){
  let data = new Uint8Array(100)
  let result = await harmonyWorker.run((bufferData, arg1) => {
    bufferData.fill(arg1, 0, bufferData.length)
    return [bufferData, [bufferData.buffer]]
  }, [data, 4], [data.buffer])
  // the result will get the modified bufferData.
  console.log(result)
}
// If there are not transferable data.
async function doSomething2(){
  let result = await harmonyWorker.run((arg1, arg2) => {
    return arg1 + arg2
  }, [2, 4])
  // the result will get 6.
  console.log(result)
}

Dependencies

None.

Readme

Keywords

Package Sidebar

Install

npm i harmony-worker

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

5.99 kB

Total Files

7

Last publish

Collaborators

  • allen.ai