|
@@ -377,16 +377,15 @@ export class DefaultKernel implements Kernel.IKernel {
|
|
|
* The promise will be rejected if the kernel status is `Dead` or if the
|
|
|
* request fails or the response is invalid.
|
|
|
*/
|
|
|
- shutdown(): Promise<void> {
|
|
|
+ async shutdown(): Promise<void> {
|
|
|
if (this.status === 'dead') {
|
|
|
this._clearSocket();
|
|
|
- this._clearState();
|
|
|
+ await this._clearState();
|
|
|
return;
|
|
|
}
|
|
|
- return Private.shutdownKernel(this.id, this.serverSettings).then(() => {
|
|
|
- this._clearState();
|
|
|
- this._clearSocket();
|
|
|
- });
|
|
|
+ await Private.shutdownKernel(this.id, this.serverSettings);
|
|
|
+ await this._clearState();
|
|
|
+ this._clearSocket();
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -851,11 +850,13 @@ export class DefaultKernel implements Kernel.IKernel {
|
|
|
/**
|
|
|
* Clear the internal state.
|
|
|
*/
|
|
|
- private _clearState(): void {
|
|
|
+ private async _clearState(): Promise<void> {
|
|
|
this._isReady = false;
|
|
|
this._pendingMessages = [];
|
|
|
+ const futuresResolved: Promise<KernelMessage.IShellMessage>[] = [];
|
|
|
this._futures.forEach(future => {
|
|
|
future.dispose();
|
|
|
+ futuresResolved.push(future.done);
|
|
|
});
|
|
|
this._comms.forEach(comm => {
|
|
|
comm.dispose();
|
|
@@ -866,6 +867,10 @@ export class DefaultKernel implements Kernel.IKernel {
|
|
|
this._comms = new Map<string, Kernel.IComm>();
|
|
|
this._displayIdToParentIds.clear();
|
|
|
this._msgIdToDisplayIds.clear();
|
|
|
+
|
|
|
+ await Promise.all(futuresResolved).catch(() => {
|
|
|
+ /* no-op */
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|