Skip to content

Commit

Permalink
subclass each PooledWorker class to avoid property collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Oct 25, 2016
1 parent eaea11c commit 7e5db2f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ function nativeWorkerFn(self) {
function createWorkersidePooledWorker(moduleId, workerId) {
var WorkerClass = self.require(moduleId);

var proto = WorkerClass.prototype;
if (proto.send) {
throw new Error('pooled worker class should not have a send property');
function Worker() {
WorkerClass.call(this);
}
if (proto.workerId) {
throw new Error('pooled worker class should not have a workerId property');
Worker.prototype = Object.create(WorkerClass.prototype);
if (Worker.prototype.send) {
throw new Error('Pooled worker class should not have a send property.');
}
proto.send = send;
proto.workerId = workerId;
if (Worker.prototype.workerId) {
throw new Error('Pooled worker class should not have a workerId property.');
}
Worker.prototype.send = send;
Worker.prototype.workerId = workerId;

workersidePooledWorkers[workerId] = new WorkerClass();
workersidePooledWorkers[workerId] = new Worker();
}

self.onmessage = function (e) {
Expand Down

0 comments on commit 7e5db2f

Please sign in to comment.