Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function request(client, invocation, options) {
const childProcess = client.childProcess,
requestMap = client.requestMap,
id = cuid(),
inputPromise = write(childProcess, _.assign({id}, invocation)),
resolveEvent = options.resolveEvent,
hidden = options.hidden,
startTime = new Date().getTime(),
outputPromise = new Promise(function (resolve, reject) {
requestMap[id] = {id, invocation, resolveEvent, hidden, deferred: {resolve, reject}};
});
return inputPromise
.then(() => outputPromise)
.finally(function () {
const endTime = (new Date().getTime() - startTime) + 'ms',
timeoutTime = endTime - 60000 * 10, // ten minutes
maxSize = 50;
let currentSize = _.size(requestMap);
function send(windowName, eventName) {
let inboundEmitter = electron.ipcMain,
window = getByName(windowName),
outboundEmitter = window && window.webContents,
eventId = cuid(),
startTime = new Date().getTime(),
args = _.map(_.slice(arguments, 2), arg => _.isBuffer(arg) ? arg.toString() : arg);
if (!outboundEmitter) {
return bluebird.resolve();
}
return new Promise(function (resolve, reject) {
// noinspection JSDuplicatedDeclaration
let response,
eventReplyName = eventName + '_reply',
timer = setInterval(function () {
if (outboundEmitter.isDestroyed()) {
log('info', 'ipc ' + eventId + ': will never complete because target window is gone', eventName);
inboundEmitter.removeListener(eventReplyName, response);
clearInterval(timer);
input(str) {
return write(this.childProcess, {id: cuid(), method: 'input', args: [str]});
}
interrupt() {
const id = cuid(),
target = 'manager',
method = 'interrupt_kernel';
return write(this.childProcess, {method, target, id});
}
return new bluebird(function (resolveInstanceId) {
let instanceId = cuid();
kernelClients[instanceId] = new bluebird(function (resolveClient) {
log('info', 'creating new python kernel process', 'creating python client');
const client = kernelsPythonClient.create(options)
.on('ready', function () {
log('info', 'new python kernel process is ready', instanceId, 'process', client.childProcess.pid, optionsForLog);
resolveClient(client);
})
.on('event', function (source, data) {
log('info', 'python kernel process event', instanceId, 'process', client.childProcess.pid, optionsForLog, {source, data});
})
.on('error', function (error) {
log('info', 'python kernel process error', instanceId, 'process', client.childProcess.pid, optionsForLog, error);
browserWindows.send('mainWindow', 'error', instanceId, errorClone.toObject(error)).catch(_.noop);
})
.on('close', function (code, signal) {