Skip to content

Commit

Permalink
Merge pull request #7820 from jasongrout/sessionkernelconnection
Browse files Browse the repository at this point in the history
Give kernel connection options to a session connection
  • Loading branch information
Steven Silvester committed Jan 24, 2020
2 parents e792600 + 9aecd51 commit 0e0e7f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
14 changes: 9 additions & 5 deletions packages/help-extension/src/index.tsx
Expand Up @@ -192,16 +192,20 @@ function activate(
if (!sessionModel.kernel || kernelInfoCache.has(sessionModel.kernel.name)) {
return;
}
const session = serviceManager.sessions.connectTo({ model: sessionModel });
// Note: .ready implies session.kernel.info is non-null
void session.kernel!.info.then(kernelInfo => {
const session = serviceManager.sessions.connectTo({
model: sessionModel,
kernelConnectionOptions: { handleComms: false }
});

void session.kernel?.info.then(kernelInfo => {
const name = session.kernel!.name;

// Check the cache second time so that, if two callbacks get scheduled,
// they don't try to add the same commands.
if (kernelInfoCache.has(sessionModel.kernel!.name)) {
if (kernelInfoCache.has(name)) {
return;
}
// Set the Kernel Info cache.
const name = session.kernel!.name;
kernelInfoCache.set(name, kernelInfo);

// Utility function to check if the current widget
Expand Down
6 changes: 6 additions & 0 deletions packages/services/src/session/default.ts
Expand Up @@ -33,6 +33,7 @@ export class SessionConnection implements Session.ISessionConnection {
this._username = options.username ?? '';
this._clientId = options.clientId ?? UUID.uuid4();
this._connectToKernel = options.connectToKernel;
this._kernelConnectionOptions = options.kernelConnectionOptions ?? {};
this.serverSettings =
options.serverSettings ?? ServerConnection.makeSettings();
this.setupKernel(options.model.kernel);
Expand Down Expand Up @@ -305,6 +306,7 @@ export class SessionConnection implements Session.ISessionConnection {
return;
}
const kc = this._connectToKernel({
...this._kernelConnectionOptions,
model,
username: this._username,
clientId: this._clientId,
Expand Down Expand Up @@ -421,4 +423,8 @@ export class SessionConnection implements Session.ISessionConnection {
private _connectToKernel: (
options: Kernel.IKernelConnection.IOptions
) => Kernel.IKernelConnection;
private _kernelConnectionOptions: Omit<
Kernel.IKernelConnection.IOptions,
'model' | 'username' | 'clientId' | 'serverSettings'
>;
}
16 changes: 12 additions & 4 deletions packages/services/src/session/session.ts
Expand Up @@ -186,6 +186,13 @@ export namespace ISessionConnection {
*/
model: IModel;

/**
* Connects to an existing kernel
*/
connectToKernel(
options: Kernel.IKernelConnection.IOptions
): Kernel.IKernelConnection;

/**
* The server settings.
*/
Expand All @@ -202,11 +209,12 @@ export namespace ISessionConnection {
clientId?: string;

/**
* Connects to an existing kernel
* Kernel connection options
*/
connectToKernel(
options: Kernel.IKernelConnection.IOptions
): Kernel.IKernelConnection;
kernelConnectionOptions?: Omit<
Kernel.IKernelConnection.IOptions,
'model' | 'username' | 'clientId' | 'serverSettings'
>;
}

/**
Expand Down

0 comments on commit 0e0e7f2

Please sign in to comment.