okiba-gang/okiba

View on GitHub
packages/worker-utils/index.js

Summary

Maintainability
A
0 mins
Test Coverage
/**
 * @module worker-utils
 * @description Set of useful functions to ease WebWorkers development
 */

/**
  * Creates a web worker starting from a function
  * @param  {Function} fn function to be included in the worker script, will be self-invoked
  * @return {WebWorker}        worker running the passed script
  */
export function createWorker(code) {
  return new Worker(
    URL.createObjectURL(
      new Blob([code])
    )
  )
}