Wait 100ms before disconnecting if a message is being sent

Change-Type: patch
This commit is contained in:
Alexis Svinartchouk 2019-02-19 14:17:45 +01:00
parent b1ab3834b6
commit c88245954d

View File

@ -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)