Skip to content

Commit 141b101

Browse files
committed
Make extensions in safari more reliable
1 parent a7d103e commit 141b101

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

packages/node-services/src/child_process.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,32 @@ function fork(path: string, argv?: string[], processOpts?: IProcessOpts) {
269269
}
270270

271271
if (isSafari) {
272-
setTimeout(() => {
273-
worker.postMessage({
274-
$type: 'worker-manager',
275-
$event: 'init',
276-
data,
277-
});
278-
}, 500);
272+
// For Safari it takes a while until the worker started, so we listen for ready message
273+
// and send a message anyway if a second passes
274+
275+
let sentReady = false;
276+
const timeout = setTimeout(() => {
277+
if (!sentReady) {
278+
worker.postMessage({
279+
$type: 'worker-manager',
280+
$event: 'init',
281+
data,
282+
});
283+
}
284+
sentReady = true;
285+
}, 1000);
286+
287+
worker.addEventListener('message', e => {
288+
if (!sentReady && e.data && e.data.$type === 'ready') {
289+
worker.postMessage({
290+
$type: 'worker-manager',
291+
$event: 'init',
292+
data,
293+
});
294+
clearTimeout(timeout);
295+
sentReady = true;
296+
}
297+
});
279298
} else {
280299
worker.postMessage({
281300
$type: 'worker-manager',

0 commit comments

Comments
 (0)