mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
Wait for clientSession to become available before running a cell. (#10796)
This commit is contained in:
@@ -39,6 +39,9 @@ export class NotebookModelStub implements INotebookModel {
|
||||
get clientSession(): IClientSession {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
get sessionLoadFinished(): Promise<void> {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
get notebookManagers(): INotebookManager[] {
|
||||
throw new Error('method not implemented.');
|
||||
}
|
||||
|
||||
@@ -373,12 +373,14 @@ export class CellModel implements ICellModel {
|
||||
|
||||
private async getOrStartKernel(notificationService: INotificationService): Promise<nb.IKernel> {
|
||||
let model = this._options.notebook;
|
||||
if (model) {
|
||||
await model.sessionLoadFinished;
|
||||
}
|
||||
let clientSession = model && model.clientSession;
|
||||
if (!clientSession) {
|
||||
this.sendNotification(notificationService, Severity.Error, localize('notebookNotReady', "The session for this notebook is not yet ready"));
|
||||
return undefined;
|
||||
} else if (!clientSession.isReady || clientSession.status === 'dead') {
|
||||
|
||||
this.sendNotification(notificationService, Severity.Info, localize('sessionNotReady', "The session for this notebook will start momentarily"));
|
||||
await clientSession.kernelChangeCompleted;
|
||||
}
|
||||
|
||||
@@ -233,6 +233,10 @@ export interface INotebookModel {
|
||||
* Client Session in the notebook, used for sending requests to the notebook service
|
||||
*/
|
||||
readonly clientSession: IClientSession;
|
||||
/**
|
||||
* Promise indicating when client session is ready to use.
|
||||
*/
|
||||
readonly sessionLoadFinished: Promise<void>;
|
||||
/**
|
||||
* LanguageInfo saved in the notebook
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,7 @@ import { find, firstIndex } from 'vs/base/common/arrays';
|
||||
import { startsWith } from 'vs/base/common/strings';
|
||||
import { notebookConstants } from 'sql/workbench/services/notebook/browser/interfaces';
|
||||
import { IAdsTelemetryService } from 'sql/platform/telemetry/common/telemetry';
|
||||
import { Deferred } from 'sql/base/common/promise';
|
||||
|
||||
/*
|
||||
* Used to control whether a message in a dialog/wizard is displayed as an error,
|
||||
@@ -54,7 +55,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
private _layoutChanged = new Emitter<void>();
|
||||
private _inErrorState: boolean = false;
|
||||
private _activeClientSession: IClientSession;
|
||||
private _sessionLoadFinished: Promise<void>;
|
||||
private _sessionLoadFinished = new Deferred<void>();
|
||||
private _onClientSessionReady = new Emitter<IClientSession>();
|
||||
private _onProviderIdChanged = new Emitter<string>();
|
||||
private _trustedMode: boolean;
|
||||
@@ -148,7 +149,6 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
return this._contentChangedEmitter.event;
|
||||
}
|
||||
|
||||
|
||||
public get isSessionReady(): boolean {
|
||||
return !!this._activeClientSession;
|
||||
}
|
||||
@@ -492,7 +492,9 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
clientSession.statusChanged(async (session) => {
|
||||
this._kernelsChangedEmitter.fire(session.kernel);
|
||||
});
|
||||
await clientSession.initialize();
|
||||
await clientSession.initialize().then(() => {
|
||||
this._sessionLoadFinished.resolve();
|
||||
});
|
||||
// By somehow we have to wait for ready, otherwise may not be called for some cases.
|
||||
await clientSession.ready;
|
||||
if (clientSession.kernel) {
|
||||
|
||||
Reference in New Issue
Block a user