Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🕰 await session manager and move exception #716

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading