forked from jupyterlab/jupyterlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
57 lines (50 loc) · 1.47 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*-----------------------------------------------------------------------------
| Copyright (c) 2014-2015, Jupyter Development Team.
|
| Distributed under the terms of the Modified BSD License.
|----------------------------------------------------------------------------*/
'use strict';
// Polyfill for ES6 Promises
import 'es6-promise';
import {
Session, utils
} from '@jupyterlab/services';
function log(text: string): void {
let el = document.getElementById('output');
el.textContent = el.textContent + '\n' + text;
console.log(text);
}
function main() {
// Start a new session.
let options: Session.IOptions = {
kernelName: 'python',
path: 'foo.ipynb'
};
let session: Session.ISession;
log('Starting session');
Session.startNew(options).then(s => {
log('Session started');
session = s;
// Rename the session.
return session.rename('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');
};
future.onDone = () => {
log('Future is fulfilled');
// Shut down the session.
session.shutdown().then(() => {
log('Session shut down');
log('Test Complete!');
});
};
}).catch(err => {
console.error(err);
log('Test Failed! See the console output for details');
});
}
window.onload = main;