Skip to content

Commit

Permalink
Always use a different SAB
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed May 17, 2022
1 parent e5dffb0 commit d1d1281
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions eslint/babel-eslint-parser/src/client.cjs
Expand Up @@ -64,23 +64,24 @@ exports.WorkerClient = class WorkerClient extends Client {

constructor() {
super((action, payload) => {
this.#signal[0] = 0;
const signal = new Int32Array(new SharedArrayBuffer(8));

const subChannel = new WorkerClient.#worker_threads.MessageChannel();

this.#worker.postMessage(
{ signal: this.#signal, port: subChannel.port1, action, payload },
{ signal, port: subChannel.port1, action, payload },
[subChannel.port1],
);

let wakeReason = Atomics.wait(this.#signal, 0, 0);
let wakeReason = Atomics.wait(signal, 0, 0);

let response;
let i = 0;
// Sometimes receiveMessageOnPort returns "undefined" instead of the
// actual response object. Try multiple times, with a timeout of 5ms
// on Atomic.wait starting from the second one.
do {
if (i > 0) wakeReason = Atomics.wait(this.#signal, 1, 0, 5);
if (i > 0) wakeReason = Atomics.wait(signal, 1, 0, 5);

response = WorkerClient.#worker_threads.receiveMessageOnPort(
subChannel.port2,
Expand Down

0 comments on commit d1d1281

Please sign in to comment.