Question

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!

Était-ce utile?

La solution

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top