UNPKG

1.27 kBPlain TextView Raw
1/*
2 * Copyright (c) Jupyter Development Team.
3 * Distributed under the terms of the Modified BSD License.
4 */
5
6import { ServiceManager } from '@jupyterlab/services';
7import { UUID } from '@lumino/coreutils';
8import { SessionContext } from './sessioncontext';
9
10/**
11 * Create a client session object.
12 */
13export 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 * A namespace for private data.
36 */
37namespace Private {
38 let manager: ServiceManager;
39
40 /**
41 * Get or create the service manager singleton.
42 */
43 export function getManager(): ServiceManager {
44 if (!manager) {
45 manager = new ServiceManager({ standby: 'never' });
46 }
47 return manager;
48 }
49}