From c88245954d7cf167eca87e18ef07bc2675b56207 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 19 Feb 2019 14:17:45 +0100 Subject: [PATCH] Wait 100ms before disconnecting if a message is being sent Change-Type: patch --- lib/gui/modules/child-writer.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/gui/modules/child-writer.js b/lib/gui/modules/child-writer.js index bead21f8..84fcbdc0 100644 --- a/lib/gui/modules/child-writer.js +++ b/lib/gui/modules/child-writer.js @@ -16,6 +16,7 @@ 'use strict' +const Bluebird = require('bluebird') const _ = require('lodash') const ipc = require('node-ipc') const sdk = require('etcher-sdk') @@ -37,6 +38,7 @@ ipc.config.silent = true // process is closed, so we can kill this process as well. ipc.config.stopRetrying = 0 +const DISCONNECT_DELAY = 100 const IPC_SERVER_ID = process.env.IPC_SERVER_ID /** @@ -82,7 +84,10 @@ const terminate = (code) => { */ const handleError = (error) => { ipc.of[IPC_SERVER_ID].emit('error', errors.toJSON(error)) - terminate(EXIT_CODES.GENERAL_ERROR) + Bluebird.delay(DISCONNECT_DELAY) + .then(() => { + terminate(EXIT_CODES.GENERAL_ERROR) + }) } /** @@ -179,7 +184,10 @@ ipc.connectTo(IPC_SERVER_ID, () => { return errors.toJSON(error) }) ipc.of[IPC_SERVER_ID].emit('done', { results }) - terminate(exitCode) + Bluebird.delay(DISCONNECT_DELAY) + .then(() => { + terminate(exitCode) + }) } /** @@ -190,7 +198,10 @@ ipc.connectTo(IPC_SERVER_ID, () => { const onAbort = () => { log('Abort') ipc.of[IPC_SERVER_ID].emit('abort') - terminate(exitCode) + Bluebird.delay(DISCONNECT_DELAY) + .then(() => { + terminate(exitCode) + }) } ipc.of[IPC_SERVER_ID].on('cancel', onAbort)