npm.io
1.0.8 • Published 7 years ago

eval-worker

Licence
ISC
Version
1.0.8
Deps
1
Size
5 kB
Vulns
0
Weekly
0

Eval Worker

This module evaluates a string in a Web Worker.

Example

const evalWorker = require("eval-worker")

evalWorker("2+3", 2000).then(result => {
  console.log(result) // 5
})
evalWorker("while(true){}", 2000).then(result => {
  console.log(result) // It is timed out after 2 seconds
})
Usage with Webpack

You will need to install worker-loader

// webpack.config.js
{
  module: {
    rules: [
      {
       test: /worker\.js$/,
       include: paths.appNodeModules, // path to your node_modules folder
       use: {
         loader: "worker-loader"
       }
      }
    ]
  }
}