Skip to content

Commit

Permalink
Refactor PR jupyterlab#7879 to use throttler
Browse files Browse the repository at this point in the history
  • Loading branch information
ikiw committed Feb 25, 2020
1 parent d3c1ffb commit 9e4f119
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/docmanager-extension/package.json
Expand Up @@ -48,6 +48,7 @@
"@lumino/algorithm": "^1.2.3",
"@lumino/coreutils": "^1.4.2",
"@lumino/disposable": "^1.3.5",
"@lumino/polling": "^1.0.4",
"@lumino/widgets": "^1.11.1"
},
"devDependencies": {
Expand Down
14 changes: 6 additions & 8 deletions packages/docmanager-extension/src/index.ts
Expand Up @@ -44,6 +44,8 @@ import { IDisposable } from '@lumino/disposable';

import { Widget } from '@lumino/widgets';

import { Throttler } from '@lumino/polling';

/**
* The command IDs used by the document manager plugin.
*/
Expand Down Expand Up @@ -244,15 +246,11 @@ ${fileTypes}`;

// callback to registry change that ensures not to invoke reload method when there is already a promise that is pending
let reloadSettingsRegistry = () => {
let promisePending = false;
let reloadThrottle = new Throttler(() =>
settingRegistry.reload(pluginId)
);

return async () => {
if (!promisePending) {
promisePending = true;
await settingRegistry.reload(pluginId);
promisePending = false;
}
};
return reloadThrottle.invoke.bind(reloadThrottle);
};

// If the document registry gains or loses a factory or file type,
Expand Down

0 comments on commit 9e4f119

Please sign in to comment.