Removed optimistic window init.

This commit is contained in:
Ahmed Ahmed 2019-10-30 14:41:37 -04:00 committed by Benjamin Staneck
parent 6f96d9f450
commit 40eaebfb73

View file

@ -129,35 +129,8 @@ module.exports = class Window {
return {session, options};
}
// Optimistically create the initial session so that when the window sends
// the first "new" IPC message, there's a session already warmed up.
let initialSession = null;
function createInitialSession() {
let {session, options} = createSession();
const initialEvents = [];
const handleData = data => initialEvents.push(['session data', data]);
const handleExit = () => {
// the warmed up session should be cleaned if exit before add a new session.
session.removeListener('data', handleData);
session.removeListener('exit', handleExit);
initialSession = null;
};
session.on('data', handleData);
session.on('exit', handleExit);
function flushEvents() {
for (let args of initialEvents) {
rpc.emit(...args);
}
session.removeListener('data', handleData);
session.removeListener('exit', handleExit);
}
return {session, options, flushEvents};
}
initialSession = createInitialSession();
rpc.on('new', extraOptions => {
const {session, options} = initialSession || createSession(extraOptions);
const {session, options} = createSession(extraOptions);
sessions.set(options.uid, session);
rpc.emit('session add', {
@ -170,13 +143,6 @@ module.exports = class Window {
activeUid: options.activeUid
});
// If this is the initial session, flush any events that might have
// occurred while the window was initializing
if (initialSession) {
initialSession.flushEvents();
initialSession = null;
}
session.on('data', data => {
rpc.emit('session data', data);
});