ソースを参照

Fix building examples

Jason Grout 5 年 前
コミット
624d49bd3d

+ 6 - 8
examples/notebook/src/commands.ts

@@ -121,26 +121,24 @@ export const SetupCommands = (
   });
   commands.addCommand(cmdIds.interrupt, {
     label: 'Interrupt',
-    execute: async () => {
-      if (nbWidget.context.session.kernel) {
-        await nbWidget.context.session.kernel.interrupt();
-      }
-    }
+    execute: async () =>
+      nbWidget.context.sessionContext.session?.kernel?.interrupt()
   });
   commands.addCommand(cmdIds.restart, {
     label: 'Restart Kernel',
-    execute: () => nbWidget.context.session.restart()
+    execute: async () =>
+      nbWidget.context.sessionContext.session?.kernel?.restart()
   });
   commands.addCommand(cmdIds.switchKernel, {
     label: 'Switch Kernel',
-    execute: () => nbWidget.context.session.selectKernel()
+    execute: async () => nbWidget.context.sessionContext.selectKernel()
   });
   commands.addCommand(cmdIds.runAndAdvance, {
     label: 'Run and Advance',
     execute: () => {
       return NotebookActions.runAndAdvance(
         nbWidget.content,
-        nbWidget.context.session
+        nbWidget.context.sessionContext
       );
     }
   });

+ 3 - 1
examples/notebook/src/index.ts

@@ -111,7 +111,9 @@ function createApp(manager: ServiceManager.IManager): void {
     nbWidget.content.activeCell && nbWidget.content.activeCell.editor;
   const model = new CompleterModel();
   const completer = new Completer({ editor, model });
-  const connector = new KernelConnector({ session: nbWidget.session });
+  const connector = new KernelConnector({
+    session: nbWidget.sessionContext.session
+  });
   const handler = new CompletionHandler({ completer, connector });
 
   // Set the handler's editor.

+ 32 - 36
packages/services/examples/browser/src/index.ts

@@ -8,7 +8,7 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';
 // @ts-ignore
 __webpack_public_path__ = URLExt.join(PageConfig.getBaseUrl(), 'example/');
 
-import { Session } from '@jupyterlab/services';
+import { Session, KernelManager, SessionManager } from '@jupyterlab/services';
 
 function log(text: string): void {
   let el = document.getElementById('output');
@@ -16,44 +16,40 @@ function log(text: string): void {
   console.log(text);
 }
 
-function main() {
+async function main() {
+  let kernelManager = new KernelManager();
+  let sessionManager = new SessionManager({ kernelManager });
+
   // Start a new session.
-  let options: Session.IOptions = {
-    kernelName: 'python',
-    path: 'foo.ipynb'
+  let options: Session.IRequest = {
+    kernel: {
+      name: 'python'
+    },
+    path: 'foo.ipynb',
+    type: 'notebook',
+    name: 'foo.ipynb'
   };
-  let session: Session.ISession;
 
-  log('Starting session');
-  Session.startNew(options)
-    .then(s => {
-      log('Session started');
-      session = s;
-      // Rename the session.
-      return session.setPath('bar.ipynb');
-    })
-    .then(() => {
-      log(`Session renamed to ${session.path}`);
-      // Execute and handle replies on the kernel.
-      let future = session.kernel.requestExecute({ code: 'a = 1' });
-      future.onReply = reply => {
-        log('Got execute reply');
-      };
-      return future.done;
-    })
-    .then(() => {
-      log('Future is fulfilled');
-      // Shut down the session.
-      return session.shutdown();
-    })
-    .then(() => {
-      log('Session shut down');
-      log('Test Complete!');
-    })
-    .catch(err => {
-      console.error(err);
-      log('Test Failed! See the console output for details');
-    });
+  try {
+    log('Starting session');
+    const sessionConnection = await sessionManager.startNew(options);
+    log('Session started');
+    await sessionConnection.setPath('bar.ipynb');
+    log(`Session renamed to ${sessionConnection.path}`);
+    let future = sessionConnection.kernel.requestExecute({ code: 'a = 1' });
+    future.onReply = reply => {
+      log('Got execute reply');
+    };
+    await future.done;
+    log('Future is fulfilled');
+    // Shut down the session.
+    await sessionConnection.shutdown();
+    log('Session shut down');
+    log('Test Complete!');
+  } catch (err) {
+    console.error(err);
+    log('Test Failed! See the console output for details');
+  }
 }
 
 window.onload = main;

+ 3 - 2
packages/services/examples/typescript-browser-with-output/src/index.ts

@@ -19,7 +19,7 @@ import {
   standardRendererFactories as initialFactories
 } from '@jupyterlab/rendermime';
 
-import { Kernel } from '@jupyterlab/services';
+import { KernelManager } from '@jupyterlab/services';
 
 async function main() {
   const code = [
@@ -30,7 +30,8 @@ async function main() {
   const rendermime = new RenderMimeRegistry({ initialFactories });
   const outputArea = new OutputArea({ model, rendermime });
 
-  const kernel = await Kernel.startNew();
+  const kernelManager = new KernelManager();
+  const kernel = await kernelManager.startNew();
   outputArea.future = kernel.requestExecute({ code });
   document.getElementById('outputarea').appendChild(outputArea.node);
   await outputArea.future.done;