Skip to content

Commit

Permalink
🕰 await session manager and move exception
Browse files Browse the repository at this point in the history
  • Loading branch information
stevejpurves committed Nov 27, 2023
1 parent a730cb3 commit bd5ff13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ class ThebeServer implements ServerRuntime, ServerRestAPI {
): Promise<ThebeSession | null> {
await this.ready;

if (!this.sessionManager?.isReady) {
if (!this.sessionManager) {
throw Error('Requesting session from a server, with no SessionManager available');
}

await this.sessionManager.ready;

// name is assumed to be a non empty string but is otherwise note required
// if a notebook name has been supplied on the path, use that otherwise use a default
// https://jupyterlab.readthedocs.io/en/3.4.x/api/modules/services.session.html#isessionoptions
Expand Down Expand Up @@ -157,12 +159,13 @@ class ThebeServer implements ServerRuntime, ServerRestAPI {

async connectToExistingSession(model: SessionIModel, rendermime: IRenderMimeRegistry) {
await this.ready;
if (!this.sessionManager?.isReady) {
if (!this.sessionManager) {
throw Error('Requesting session from a server, with no SessionManager available');
}

const connection = this.sessionManager?.connectTo({ model });
await this.sessionManager.ready;

const connection = this.sessionManager?.connectTo({ model });
return new ThebeSession(this, connection, rendermime);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/hooks/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function useNotebookBase() {

const executeAll = (options?: NotebookExecuteOptions) => {
if (!notebook) throw new Error('executeAll called before notebook available');
if (!session) throw new Error('executeAll called before session available');
options?.before?.();
setExecuting(true);
return notebook
Expand All @@ -69,6 +70,7 @@ export function useNotebookBase() {
options?: NotebookExecuteOptions,
) => {
if (!notebook) throw new Error('executeSome called before notebook available');
if (!session) throw new Error('executeAll called before session available');
options?.before?.();
setExecuting(true);
const filteredCells = notebook.cells.filter(predicate).map((c) => c.id);
Expand Down

0 comments on commit bd5ff13

Please sign in to comment.