Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Altered webworker-child to permit the global worker object to be passed by reference. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/trivial/master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var Worker = require("webworker").Worker;
var worker = new Worker(__dirname + "/worker.js");
worker.onmessage = function (message) {
console.log(message.data);
worker.terminate();
};
worker.postMessage("Hello, World!");

6 changes: 6 additions & 0 deletions examples/trivial/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var worker = this;
worker.onmessage = function (message) {
// echo
worker.postMessage(message.data);
}

4 changes: 2 additions & 2 deletions lib/webworker-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ws.addListener('open', function() {
process.addListener('uncaughtException', exceptionHandler);

// Execute the worker
scriptObj.runInNewContext(workerCtx);
scriptObj.runInThisContext();
});

// Construt the Script object to host the worker's code
Expand All @@ -145,7 +145,7 @@ default:
}

// Set up the context for the worker instance
var workerCtx = {};
var workerCtx = global;

// Context elements required for node.js
//
Expand Down