From 4e238012850544d9d5388b3bd933a987d3e8b522 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Fri, 22 Jan 2021 18:45:44 +0100 Subject: [PATCH] Use a Poll instead of setInterval --- packages/notebook-extension/package.json | 1 + packages/notebook-extension/src/index.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/notebook-extension/package.json b/packages/notebook-extension/package.json index f54347860..1407bd2db 100644 --- a/packages/notebook-extension/package.json +++ b/packages/notebook-extension/package.json @@ -44,6 +44,7 @@ "@jupyterlab/apputils": "^3.0.0", "@jupyterlab/docmanager": "^3.0.0", "@jupyterlab/notebook": "^3.0.0", + "@lumino/polling": "^1.3.3", "@lumino/widgets": "^1.14.0" }, "devDependencies": { diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index c50fcb873..72adc3c11 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -20,6 +20,8 @@ import { IClassicShell } from '@jupyterlab-classic/application'; +import { Poll } from '@lumino/polling'; + import { Widget } from '@lumino/widgets'; /** @@ -84,9 +86,16 @@ const checkpoints: JupyterFrontEndPlugin = { if (classicShell) { classicShell.currentChanged.connect(onChange); } - // TODO: replace by a Poll - onChange(); - setInterval(onChange, 2000); + + new Poll({ + auto: true, + factory: () => onChange(), + frequency: { + interval: 2000, + backoff: false + }, + standby: 'when-hidden' + }); } };