Skip to content

Commit

Permalink
Changes to jupyterlab_widgets plugin and manager to make the KernelWi…
Browse files Browse the repository at this point in the history
…dgetManager a singleton on a per kernel basis.

Other fixes to make widgets more accessible.
  • Loading branch information
Alan Fleming committed May 19, 2024
1 parent 7741dbb commit 1c4d1ad
Show file tree
Hide file tree
Showing 5 changed files with 271 additions and 132 deletions.
8 changes: 7 additions & 1 deletion packages/base-manager/src/manager-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ export abstract class ManagerBase implements IWidgetManager {
*
* If you would like to synchronously test if a model exists, use .has_model().
*/
async get_model(model_id: string): Promise<WidgetModel> {
async get_model(model_id: string, timeout = 1000): Promise<WidgetModel> {
let count = 0;
while (!this._models[model_id] && count++ < timeout / 10) {
await sleep(10);
}
const modelPromise = this._models[model_id];
if (modelPromise === undefined) {
throw new Error(`widget model '${model_id}' not found`);
Expand Down Expand Up @@ -919,6 +923,8 @@ export function serialize_state(
return { version_major: 2, version_minor: 0, state: state };
}

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

namespace Private {
/**
* Data promised when a comm info request resolves.
Expand Down
Loading

0 comments on commit 1c4d1ad

Please sign in to comment.