Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Remove ensureSessionReady, use _ready promise
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Dec 11, 2019
1 parent 9162bfb commit 9645cc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
11 changes: 0 additions & 11 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { IClientSession } from '@jupyterlab/apputils';

import { IDisposable } from '@phosphor/disposable';

import { ISignal, Signal } from '@phosphor/signaling';
Expand Down Expand Up @@ -307,8 +305,6 @@ export class DebugService implements IDebugger, IDisposable {
if (!this.session.isStarted) {
return;
}
// Workaround: this should not be called before the session has started
await this.ensureSessionReady();
if (!path) {
const dumpedCell = await this.dumpCell(code);
path = dumpedCell.sourcePath;
Expand Down Expand Up @@ -436,8 +432,6 @@ export class DebugService implements IDebugger, IDisposable {
breakpoints: DebugProtocol.SourceBreakpoint[],
path: string
) => {
// Workaround: this should not be called before the session has started
await this.ensureSessionReady();
return await this.session.sendRequest('setBreakpoints', {
breakpoints: breakpoints,
source: { path },
Expand All @@ -462,11 +456,6 @@ export class DebugService implements IDebugger, IDisposable {
});
};

private async ensureSessionReady(): Promise<void> {
const client = this.session.client as IClientSession;
return client.ready;
}

private clearModel() {
this._model.callstack.frames = [];
this._model.variables.scopes = [];
Expand Down
24 changes: 13 additions & 11 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,22 @@ export class DebugSession implements IDebugger.ISession {

this._client = client;

if (client) {
if (this._client) {
this._client.iopubMessage.connect(this._handleEvent, this);

if (this.client instanceof ClientSession) {
this._ready = this.client.ready;
} else {
this._ready = this.client.kernel.ready;
}
}
}

/**
* Return the kernel info for the debug session.
*/
get kernelInfo(): IDebugger.ISession.IInfoReply | null {
const kernel = this.client.kernel;
if (!kernel) {
return null;
}
return kernel.info as IDebugger.ISession.IInfoReply;
return (this.client.kernel?.info as IDebugger.ISession.IInfoReply) ?? null;
}

/**
Expand Down Expand Up @@ -108,6 +110,7 @@ export class DebugSession implements IDebugger.ISession {
* Start a new debug session
*/
async start(): Promise<void> {
await this._ready;
await this.sendRequest('initialize', {
clientID: 'jupyterlab',
clientName: 'JupyterLab',
Expand All @@ -130,6 +133,7 @@ export class DebugSession implements IDebugger.ISession {
* Stop the running debug session.
*/
async stop(): Promise<void> {
await this._ready;
await this.sendRequest('disconnect', {
restart: false,
terminateDebuggee: true
Expand All @@ -141,11 +145,7 @@ export class DebugSession implements IDebugger.ISession {
* Restore the state of a debug session.
*/
async restoreState(): Promise<IDebugger.ISession.Response['debugInfo']> {
if (this.client instanceof ClientSession) {
await this.client.ready;
} else {
await this.client.kernel.ready;
}
await this._ready;
const message = await this.sendRequest('debugInfo', {});
this._isStarted = message.body.isStarted;
return message;
Expand All @@ -160,6 +160,7 @@ export class DebugSession implements IDebugger.ISession {
command: K,
args: IDebugger.ISession.Request[K]
): Promise<IDebugger.ISession.Response[K]> {
await this._ready;
const message = await this._sendDebugMessage({
type: 'request',
seq: this._seq++,
Expand Down Expand Up @@ -209,6 +210,7 @@ export class DebugSession implements IDebugger.ISession {
}

private _client: IClientSession | Session.ISession;
private _ready: Promise<void>;
private _disposed = new Signal<this, void>(this);
private _isDisposed: boolean = false;
private _isStarted: boolean = false;
Expand Down

0 comments on commit 9645cc8

Please sign in to comment.