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!

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

How to use these templates?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.