3

I tried to adopt the shell.cc sample from the V8 distribution package for my own purposes.

I want to spawn a web-worker to execute a long-running script, and execute:

var myWorker = new Worker("my_task.js");

But I receive the following error message:

(shell):1: ReferenceError: Worker is not defined
var myWorker = new Worker("my_task.js");
                   ^
ReferenceError: Worker is not defined
    at (shell):1:20

Is there a way to activate Web Workers in the V8 Engine?

Thank you in advance for any help on this issue!

jfriend00
  • 683,504
  • 96
  • 985
  • 979
Edmund Moshammer
  • 688
  • 7
  • 19

2 Answers2

3

I think you'd use the Child Process library for node or one of the other libraries that implements threading. As far as I know, web workers are a browser thing, not part of the standard node.js implementation and if you want that sort of API, you would need to use a third party library that implements something like that API.

Other useful references:

Lightweight Web Worker API implementation with native threads

Concurrency on Node Discussion

Web Worker implementation in node

Community
  • 1
  • 1
jfriend00
  • 683,504
  • 96
  • 985
  • 979
2

Too late though: But for any one still searching for it:

Check d8.cc file in v8 source code , it exposes Worker Template: enter image description here

Anurag Vohra
  • 1,781
  • 12
  • 28