|
@@ -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;
|