Skip to content

Commit

Permalink
Fix issue allegro#21: "node-worker don't run in windows"
Browse files Browse the repository at this point in the history
- in transport.send(), only call pipe.write once

Payload of second call (containing `serializedMessage`) was getting lost, or at least not being received.

I could not discern the exact root cause (something something pipes on windows).

Tests are all passing on linux and windows.
  • Loading branch information
dhharker committed Aug 28, 2018
1 parent eb32cff commit 14f69a1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/worker/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ class Transport extends EventEmitter {

send(message) {
const serializedMessage = msgpack.encode(message);
const header = new Uint32Array([ serializedMessage.byteLength ]);
const payloadLength = serializedMessage.byteLength;

this.pipe.write(Buffer.from(header.buffer));
this.pipe.write(serializedMessage);
const header = new Uint32Array([payloadLength]);
const headerLength = Uint32Array.BYTES_PER_ELEMENT * header.length;

this.pipe.write(
Buffer.concat(
[Buffer.from(header.buffer), serializedMessage],
payloadLength + headerLength
)
);
}
}

module.exports = Transport;
module.exports = Transport;

0 comments on commit 14f69a1

Please sign in to comment.