MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / CodeExecution

Class CodeExecution

src/kernels/execution/codeExecution.ts:37–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 * Further details here https://github.com/microsoft/vscode-jupyter/issues/232 & https://github.com/jupyter/jupyter_client/issues/297
36 */
37export class CodeExecution implements ICodeExecution, IDisposable {
38 public readonly type = 'code';
39 public get done(): Promise<void> {
40 return this._done.promise;
41 }
42 public get result(): Promise<void> {
43 return this._done.promise;
44 }
45 private readonly _onDidEmitOutput = new EventEmitter<NotebookCellOutput>();
46 public readonly onDidEmitOutput = this._onDidEmitOutput.event;
47 private readonly _onRequestSent = new EventEmitter<void>();
48 public readonly onRequestSent = this._onRequestSent.event;
49 private readonly _onRequestAcknowledge = new EventEmitter<void>();
50 public readonly onRequestAcknowledged = this._onRequestAcknowledge.event;
51 private readonly _done = createDeferred<void>();
52 private started?: boolean;
53
54 private _completed?: boolean;
55 private cancelHandled = false;
56 private disposed?: boolean;
57 private request: Kernel.IShellFuture<KernelMessage.IExecuteRequestMsg, KernelMessage.IExecuteReplyMsg> | undefined;
58 private readonly disposables: IDisposable[] = [];
59 private session?: IKernelSession;
60 private cancelRequested?: boolean;
61 public readonly executionId: string;
62 private constructor(
63 public readonly code: string,
64 public readonly extensionId: string
65 ) {
66 let executionId = extensionIdsPerExtension.get(extensionId) || 0;
67 executionId += 1;
68 extensionIdsPerExtension.set(extensionId, executionId);
69 this.executionId = `${extensionId}-${executionId}`;
70 this.disposables.push(this._onDidEmitOutput);
71 }
72
73 public static fromCode(code: string, extensionId: string) {
74 return new CodeExecution(code, extensionId);
75 }
76 public async start(session: IKernelSession) {
77 this.session = session;
78 if (this.cancelHandled) {
79 traceExecMessage(this.extensionId, this.executionId, 'Not starting as it was cancelled');
80 return;
81 }
82 traceExecMessage(this.extensionId, this.executionId, 'Start Code execution');
83 logger.ci(`Code Exec contents ${this.code.substring(0, 50)}...`);
84 if (!session.kernel || session.kernel.isDisposed || session.isDisposed) {
85 this._done.reject(new SessionDisposedError());
86 return;
87 }
88
89 if (this.started) {
90 traceExecMessage(
91 this.extensionId,
92 this.executionId,
93 'Code has already been started yet CodeExecution.Start invoked again'
94 );

Callers

nothing calls this directly

Calls 1

createDeferredFunction · 0.90

Tested by

no test coverage detected