Fix a few notebook promises (#9315)

* Fix a few notebook promises

* Add a _ before sessionDetails

* Change to onUnexpectedError
This commit is contained in:
Amir Omidi
2020-02-26 11:58:56 -08:00
committed by GitHub
parent 6cf82d2611
commit 924815353d
2 changed files with 29 additions and 21 deletions

View File

@@ -235,7 +235,9 @@ class SessionManagerWrapper implements azdata.nb.SessionManager {
private async doStartNew(options: azdata.nb.ISessionOptions): Promise<azdata.nb.ISession> { private async doStartNew(options: azdata.nb.ISessionOptions): Promise<azdata.nb.ISession> {
let sessionDetails = await this._proxy.ext.$startNewSession(this.managerHandle, options); let sessionDetails = await this._proxy.ext.$startNewSession(this.managerHandle, options);
return new SessionWrapper(this._proxy, sessionDetails); const sessionManager = new SessionWrapper(this._proxy, sessionDetails);
await sessionManager.initialize();
return sessionManager;
} }
shutdown(id: string): Thenable<void> { shutdown(id: string): Thenable<void> {
@@ -257,34 +259,39 @@ class SessionManagerWrapper implements azdata.nb.SessionManager {
class SessionWrapper implements azdata.nb.ISession { class SessionWrapper implements azdata.nb.ISession {
private _kernel: KernelWrapper; private _kernel: KernelWrapper;
constructor(private _proxy: Proxies, private sessionDetails: INotebookSessionDetails) { constructor(private _proxy: Proxies, private _sessionDetails: INotebookSessionDetails) {
if (sessionDetails && sessionDetails.kernelDetails) {
this._kernel = new KernelWrapper(_proxy, sessionDetails.kernelDetails); }
public async initialize(): Promise<void> {
if (this._sessionDetails && this._sessionDetails.kernelDetails) {
this._kernel = new KernelWrapper(this._proxy, this._sessionDetails.kernelDetails);
return this._kernel.initialize();
} }
} }
get canChangeKernels(): boolean { get canChangeKernels(): boolean {
return this.sessionDetails.canChangeKernels; return this._sessionDetails.canChangeKernels;
} }
get id(): string { get id(): string {
return this.sessionDetails.id; return this._sessionDetails.id;
} }
get path(): string { get path(): string {
return this.sessionDetails.path; return this._sessionDetails.path;
} }
get name(): string { get name(): string {
return this.sessionDetails.name; return this._sessionDetails.name;
} }
get type(): string { get type(): string {
return this.sessionDetails.type; return this._sessionDetails.type;
} }
get status(): azdata.nb.KernelStatus { get status(): azdata.nb.KernelStatus {
return this.sessionDetails.status as azdata.nb.KernelStatus; return this._sessionDetails.status as azdata.nb.KernelStatus;
} }
get kernel(): azdata.nb.IKernel { get kernel(): azdata.nb.IKernel {
@@ -307,17 +314,18 @@ class SessionWrapper implements azdata.nb.ISession {
} }
private async doChangeKernel(kernelInfo: azdata.nb.IKernelSpec): Promise<azdata.nb.IKernel> { private async doChangeKernel(kernelInfo: azdata.nb.IKernelSpec): Promise<azdata.nb.IKernel> {
let kernelDetails = await this._proxy.ext.$changeKernel(this.sessionDetails.sessionId, kernelInfo); let kernelDetails = await this._proxy.ext.$changeKernel(this._sessionDetails.sessionId, kernelInfo);
this._kernel = new KernelWrapper(this._proxy, kernelDetails); this._kernel = new KernelWrapper(this._proxy, kernelDetails);
await this._kernel.initialize();
return this._kernel; return this._kernel;
} }
private async doConfigureKernel(kernelInfo: azdata.nb.IKernelSpec): Promise<void> { private async doConfigureKernel(kernelInfo: azdata.nb.IKernelSpec): Promise<void> {
await this._proxy.ext.$configureKernel(this.sessionDetails.sessionId, kernelInfo); await this._proxy.ext.$configureKernel(this._sessionDetails.sessionId, kernelInfo);
} }
private async doConfigureConnection(connection: azdata.IConnectionProfile): Promise<void> { private async doConfigureConnection(connection: azdata.IConnectionProfile): Promise<void> {
await this._proxy.ext.$configureConnection(this.sessionDetails.sessionId, connection); await this._proxy.ext.$configureConnection(this._sessionDetails.sessionId, connection);
} }
} }
@@ -325,13 +333,12 @@ class KernelWrapper implements azdata.nb.IKernel {
private _isReady: boolean = false; private _isReady: boolean = false;
private _ready = new Deferred<void>(); private _ready = new Deferred<void>();
private _info: azdata.nb.IInfoReply; private _info: azdata.nb.IInfoReply;
constructor(private _proxy: Proxies, private kernelDetails: INotebookKernelDetails) { constructor(private readonly _proxy: Proxies, private readonly kernelDetails: INotebookKernelDetails) {
this.initialize(kernelDetails);
} }
private async initialize(kernelDetails: INotebookKernelDetails): Promise<void> { public async initialize(): Promise<void> {
try { try {
this._info = await this._proxy.ext.$getKernelReadyStatus(kernelDetails.kernelId); this._info = await this._proxy.ext.$getKernelReadyStatus(this.kernelDetails.kernelId);
this._isReady = true; this._isReady = true;
this._ready.resolve(); this._ready.resolve();
} catch (error) { } catch (error) {

View File

@@ -34,6 +34,7 @@ import * as TelemetryKeys from 'sql/platform/telemetry/common/telemetryKeys';
import { attachButtonStyler } from 'sql/platform/theme/common/styler'; import { attachButtonStyler } from 'sql/platform/theme/common/styler';
import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar'; import { Taskbar } from 'sql/base/browser/ui/taskbar/taskbar';
import { find, fill } from 'vs/base/common/arrays'; import { find, fill } from 'vs/base/common/arrays';
import { onUnexpectedError } from 'vs/base/common/errors';
export const NOTEBOOKSVIEW_SELECTOR: string = 'notebooksview-component'; export const NOTEBOOKSVIEW_SELECTOR: string = 'notebooksview-component';
@@ -407,14 +408,14 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
break; break;
} }
} }
this.openLastNRun(targetNotebook, barId, 5); this.openLastNRun(targetNotebook, barId, 5).catch(onUnexpectedError);
e.stopPropagation(); e.stopPropagation();
}); });
// cache the dataview for future use // cache the dataview for future use
this._notebookCacheObject.dataView = this.dataView; this._notebookCacheObject.dataView = this.dataView;
this.filterValueMap['start'] = [[], this.dataView.getItems()]; this.filterValueMap['start'] = [[], this.dataView.getItems()];
this.loadJobHistories(); this.loadJobHistories().catch(onUnexpectedError);
} }
private highlightErrorRows(e) { private highlightErrorRows(e) {
@@ -582,7 +583,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
this.rowDetail.applyTemplateNewLineHeight(item, true); this.rowDetail.applyTemplateNewLineHeight(item, true);
} }
private async loadJobHistories() { private async loadJobHistories(): Promise<void> {
if (this.notebooks) { if (this.notebooks) {
let ownerUri: string = this._commonService.connectionManagementService.connectionInfo.ownerUri; let ownerUri: string = this._commonService.connectionManagementService.connectionInfo.ownerUri;
let separatedJobs = this.separateFailingJobs(); let separatedJobs = this.separateFailingJobs();
@@ -590,7 +591,7 @@ export class NotebooksViewComponent extends JobManagementView implements OnInit,
// so they can be expanded quicker // so they can be expanded quicker
let failing = separatedJobs[0]; let failing = separatedJobs[0];
let passing = separatedJobs[1]; let passing = separatedJobs[1];
Promise.all([this.curateJobHistory(failing, ownerUri), this.curateJobHistory(passing, ownerUri)]); await Promise.all([this.curateJobHistory(failing, ownerUri), this.curateJobHistory(passing, ownerUri)]);
} }
} }