josdejong / workerpool

Offload tasks to a pool of workers on node.js and in the browser
Apache License 2.0
2.04k stars 148 forks source link

Transfer from a worker to the main thread doesn't work in browser. #454

Open LeonidPolukhin opened 2 months ago

LeonidPolukhin commented 2 months ago

Worker returns Transfer object like

const array = new Float32Array(data);
return new workerpool.Transfer(array, [array.buffer]);

In worker.js:

if (result instanceof Transfer) { 
    worker.send({
        id: request.id,
        result: result.message,
        error: null
    }, result.transfer);
}

but worker.send (message) takes only one argument skipping transfer so no transferring happens. See worker.js: 27

  worker.send = function (message) {
    postMessage(message);
  };