Skip to content

Commit

Permalink
Merge pull request #7694 from jasongrout/sessionchanged
Browse files Browse the repository at this point in the history
Be more careful about sessioncontext kernelChanged and sessionChanged signal emissions
  • Loading branch information
afshin committed Dec 29, 2019
2 parents 5942e1d + 303abb4 commit 1fc7a3d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
10 changes: 6 additions & 4 deletions packages/apputils/src/sessioncontext.tsx
Expand Up @@ -512,6 +512,8 @@ export class SessionContext implements ISessionContext {
return;
}
this._isDisposed = true;
this._disposed.emit();

if (this._session) {
if (this.kernelPreference.shutdownOnDispose) {
// Fire and forget the session shutdown request
Expand All @@ -531,7 +533,6 @@ export class SessionContext implements ISessionContext {
this._busyDisposable.dispose();
this._busyDisposable = null;
}
this._disposed.emit();
Signal.clearData(this);
}

Expand Down Expand Up @@ -765,9 +766,11 @@ export class SessionContext implements ISessionContext {
private _onSessionDisposed(): void {
if (this._session) {
this._session.dispose();
const oldValue = this._session;
this._session = null;
const newValue = this._session;
this._sessionChanged.emit({ name: 'session', oldValue, newValue });
}
this._session = null;
this._terminated.emit(undefined);
}

/**
Expand Down Expand Up @@ -873,7 +876,6 @@ export class SessionContext implements ISessionContext {
private _initializing = false;
private _initPromise = new PromiseDelegate<boolean>();
private _isReady = false;
private _terminated = new Signal<this, void>(this);
private _kernelChanged = new Signal<
this,
Session.ISessionConnection.IKernelChangedArgs
Expand Down
24 changes: 13 additions & 11 deletions packages/console-extension/src/index.ts
Expand Up @@ -162,17 +162,19 @@ async function activateConsole(
// Handle state restoration.
void restorer.restore(tracker, {
command: CommandIDs.create,
args: widget => ({
path: widget.content.console.sessionContext.session?.path,
name: widget.content.console.sessionContext.session?.name,
kernelPreference: {
name: widget.content.console.sessionContext.kernelPreference.name,
language:
widget.content.console.sessionContext.kernelPreference.language
}
}),
name: widget =>
widget.content.console.sessionContext.session?.path ?? UUID.uuid4(),
args: widget => {
const {
path,
name,
kernelPreference
} = widget.content.console.sessionContext;
return {
path,
name,
kernelPreference: { ...kernelPreference }
};
},
name: widget => widget.content.console.sessionContext.path ?? UUID.uuid4(),
when: manager.ready
});

Expand Down
11 changes: 9 additions & 2 deletions packages/services/src/session/default.ts
Expand Up @@ -206,8 +206,15 @@ export class SessionConnection implements Session.ISessionConnection {
}
this._isDisposed = true;
this._disposed.emit();
this._kernel?.dispose();
this._kernel = null;

if (this._kernel) {
this._kernel.dispose();
let oldValue = this._kernel;
this._kernel = null;
let newValue = this._kernel;
this._kernelChanged.emit({ name: 'kernel', oldValue, newValue });
}

Signal.clearData(this);
}

Expand Down

0 comments on commit 1fc7a3d

Please sign in to comment.