1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import { ServiceManager } from '@jupyterlab/services';
|
7 | import { UUID } from '@lumino/coreutils';
|
8 | import { SessionContext } from './sessioncontext';
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export async function createSessionContext(
|
14 | options: Partial<SessionContext.IOptions> = {}
|
15 | ): Promise<SessionContext> {
|
16 | const manager = options.sessionManager ?? Private.getManager().sessions;
|
17 | const specsManager = options.specsManager ?? Private.getManager().kernelspecs;
|
18 |
|
19 | await Promise.all([manager.ready, specsManager.ready]);
|
20 | return new SessionContext({
|
21 | sessionManager: manager,
|
22 | specsManager,
|
23 | path: options.path ?? UUID.uuid4(),
|
24 | name: options.name,
|
25 | type: options.type,
|
26 | kernelPreference: options.kernelPreference ?? {
|
27 | shouldStart: true,
|
28 | canStart: true,
|
29 | name: specsManager.specs?.default
|
30 | }
|
31 | });
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | namespace Private {
|
38 | let manager: ServiceManager;
|
39 |
|
40 | |
41 |
|
42 |
|
43 | export function getManager(): ServiceManager {
|
44 | if (!manager) {
|
45 | manager = new ServiceManager({ standby: 'never' });
|
46 | }
|
47 | return manager;
|
48 | }
|
49 | }
|