backend-dev-utils: remove message listener when IPC client reuqest times out

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-02-05 16:11:47 +01:00
parent 4f5bf2835c
commit 81c06d5a4a
+7 -4
View File
@@ -84,10 +84,7 @@ export class BackstageIpcClient {
return;
}
const timeout = setTimeout(() => {
reject(new Error('IPC request timed out'));
}, 1000);
timeout.unref();
let timeout: NodeJS.Timeout | undefined = undefined;
const messageHandler = (response: Response) => {
if (response?.type !== responseType) {
@@ -111,6 +108,12 @@ export class BackstageIpcClient {
process.removeListener('message', messageHandler);
};
timeout = setTimeout(() => {
reject(new Error(`IPC request '${method}' with ID ${id} timed out`));
process.removeListener('message', messageHandler);
}, 5000);
timeout.unref();
process.addListener('message', messageHandler as () => void);
});
});