Skip to content

Commit

Permalink
Work around a change in the worker_threads module
Browse files Browse the repository at this point in the history
Fixes #1879
  • Loading branch information
julienw committed Mar 25, 2019
1 parent b7ee402 commit c6d61f0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/__mocks__/worker-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ class NodeWorker {
message: mixed,
transfer?: Array<ArrayBuffer | MessagePort | ImageBitmap>
) {
this._instance.postMessage({ data: message }, transfer);
let payload = message;

// Starting with node v11.12, postMessage sends the payload using the same
// semantics than Web Workers. This code adds the support for older node
// versions. We can remove this thin compatibility layers when we stop
// supporting these node versions.
const nodeVersion = process.versions.node;
const [major, minor] = nodeVersion.split('.');

if (+major < 11 || (+major === 11 && +minor < 12)) {
payload = { data: message };
}
this._instance.postMessage(payload, transfer);
}

onMessage = (message: Object) => {
Expand Down

0 comments on commit c6d61f0

Please sign in to comment.