Skip to content

Commit

Permalink
Removed optimistic window init.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmed Ahmed authored and Stanzilla committed Nov 2, 2019
1 parent 6f96d9f commit 40eaebf
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions app/ui/window.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 40eaebf

Please sign in to comment.