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

Switch to using Lumino polling package. #7617

Merged
merged 2 commits into from Dec 12, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/application/package.json
Expand Up @@ -49,6 +49,7 @@
"@lumino/coreutils": "^1.3.1",
"@lumino/disposable": "^1.3.0",
"@lumino/messaging": "^1.3.0",
"@lumino/polling": "^1.0.1",
"@lumino/properties": "^1.1.3",
"@lumino/signaling": "^1.3.0",
"@lumino/widgets": "^1.9.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/application/src/shell.ts
@@ -1,8 +1,6 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Debouncer } from '@jupyterlab/coreutils';

import { DocumentRegistry } from '@jupyterlab/docregistry';

import { DockPanelSvg, TabBarSvg } from '@jupyterlab/ui-components';
Expand All @@ -13,6 +11,8 @@ import { PromiseDelegate, Token } from '@lumino/coreutils';

import { Message, MessageLoop, IMessageHandler } from '@lumino/messaging';

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

import { ISignal, Signal } from '@lumino/signaling';

import {
Expand Down
1 change: 1 addition & 0 deletions packages/apputils-extension/package.json
Expand Up @@ -46,6 +46,7 @@
"@lumino/commands": "^1.7.0",
"@lumino/coreutils": "^1.3.1",
"@lumino/disposable": "^1.3.0",
"@lumino/polling": "^1.0.1",
"@lumino/widgets": "^1.9.0",
"es6-promise": "~4.2.6"
},
Expand Down
16 changes: 9 additions & 7 deletions packages/apputils-extension/src/index.ts
Expand Up @@ -9,6 +9,7 @@ import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';

import {
Dialog,
ICommandPalette,
Expand All @@ -17,20 +18,21 @@ import {
WindowResolver,
Printing
} from '@jupyterlab/apputils';
import {
Debouncer,
IStateDB,
StateDB,
Throttler,
URLExt
} from '@jupyterlab/coreutils';

import { IStateDB, StateDB, URLExt } from '@jupyterlab/coreutils';

import { defaultIconRegistry } from '@jupyterlab/ui-components';

import { PromiseDelegate } from '@lumino/coreutils';

import { DisposableDelegate } from '@lumino/disposable';

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

import { Palette } from './palette';

import { settingsPlugin } from './settingsplugin';

import { themesPlugin, themesPaletteMenuPlugin } from './themeplugins';

/**
Expand Down
1 change: 1 addition & 0 deletions packages/codemirror/package.json
Expand Up @@ -42,6 +42,7 @@
"@lumino/commands": "^1.7.0",
"@lumino/coreutils": "^1.3.1",
"@lumino/disposable": "^1.3.0",
"@lumino/polling": "^1.0.1",
"@lumino/signaling": "^1.3.0",
"@lumino/widgets": "^1.9.0",
"codemirror": "~5.47.0",
Expand Down
22 changes: 10 additions & 12 deletions packages/codemirror/src/editor.ts
Expand Up @@ -5,28 +5,26 @@

import CodeMirror from 'codemirror';

import { JSONExt } from '@lumino/coreutils';

import { ArrayExt } from '@lumino/algorithm';

import { IDisposable, DisposableDelegate } from '@lumino/disposable';

import { Signal } from '@lumino/signaling';

import { showDialog } from '@jupyterlab/apputils';

import { Poll } from '@jupyterlab/coreutils';

import { CodeEditor } from '@jupyterlab/codeeditor';

import { UUID } from '@lumino/coreutils';

import {
IObservableMap,
IObservableString,
ICollaborator
} from '@jupyterlab/observables';

import { ArrayExt } from '@lumino/algorithm';

import { JSONExt, UUID } from '@lumino/coreutils';

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

import { IDisposable, DisposableDelegate } from '@lumino/disposable';

import { Signal } from '@lumino/signaling';

import { Mode } from './mode';

import 'codemirror/addon/comment/comment.js';
Expand Down
2 changes: 0 additions & 2 deletions packages/coreutils/src/index.ts
Expand Up @@ -8,8 +8,6 @@ export * from './markdowncodeblocks';
export * from './nbformat';
export * from './pageconfig';
export * from './path';
export * from './poll';
export * from './ratelimiter';
export * from './restorablepool';
export * from './settingregistry';
export * from './statedb';
Expand Down
168 changes: 0 additions & 168 deletions packages/coreutils/src/interfaces.ts
Expand Up @@ -177,174 +177,6 @@ export interface IObjectPool<T extends IObservableDisposable>
has(obj: T): boolean;
}

/**
* A readonly poll that calls an asynchronous function with each tick.
*
* @typeparam T - The resolved type of the factory's promises.
*
* @typeparam U - The rejected type of the factory's promises.
*
* @typeparam V - The type to extend the phases supported by a poll.
*/
export interface IPoll<T, U, V extends string> {
/**
* A signal emitted when the poll is disposed.
*/
readonly disposed: ISignal<this, void>;

/**
* The polling frequency data.
*/
readonly frequency: IPoll.Frequency;

/**
* Whether the poll is disposed.
*/
readonly isDisposed: boolean;

/**
* The name of the poll.
*/
readonly name: string;

/**
* The poll state, which is the content of the currently-scheduled poll tick.
*/
readonly state: IPoll.State<T, U, V>;

/**
* A promise that resolves when the currently-scheduled tick completes.
*
* #### Notes
* Usually this will resolve after `state.interval` milliseconds from
* `state.timestamp`. It can resolve earlier if the user starts or refreshes the
* poll, etc.
*/
readonly tick: Promise<IPoll<T, U, V>>;

/**
* A signal emitted when the poll state changes, i.e., a new tick is scheduled.
*/
readonly ticked: ISignal<IPoll<T, U, V>, IPoll.State<T, U, V>>;
}

/**
* A namespace for `IPoll` types.
*/
export namespace IPoll {
/**
* The polling frequency parameters.
*
* #### Notes
* We implement the "decorrelated jitter" strategy from
* https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/.
* Essentially, if consecutive retries are needed, we choose an integer:
* `sleep = min(max, rand(interval, backoff * sleep))`
* This ensures that the poll is never less than `interval`, and nicely
* spreads out retries for consecutive tries. Over time, if (interval < max),
* the random number will be above `max` about (1 - 1/backoff) of the time
* (sleeping the `max`), and the rest of the time the sleep will be a random
* number below `max`, decorrelating our trigger time from other pollers.
*/
export type Frequency = {
/**
* Whether poll frequency backs off (boolean) or the backoff growth rate
* (float > 1).
*
* #### Notes
* If `true`, the default backoff growth rate is `3`.
*/
readonly backoff: boolean | number;

/**
* The basic polling interval in milliseconds (integer).
*/
readonly interval: number;

/**
* The maximum milliseconds (integer) between poll requests.
*/
readonly max: number;
};

/**
* The phase of the poll when the current tick was scheduled.
*
* @typeparam T - A type for any additional tick phases a poll supports.
*/
export type Phase<T extends string> =
| T
| 'constructed'
| 'disposed'
| 'reconnected'
| 'refreshed'
| 'rejected'
| 'resolved'
| 'standby'
| 'started'
| 'stopped';

/**
* Definition of poll state at any given time.
*
* @typeparam T - The resolved type of the factory's promises.
*
* @typeparam U - The rejected type of the factory's promises.
*
* @typeparam V - The type to extend the phases supported by a poll.
*/
export type State<T, U, V extends string> = {
/**
* The number of milliseconds until the current tick resolves.
*/
readonly interval: number;

/**
* The payload of the last poll resolution or rejection.
*
* #### Notes
* The payload is `null` unless the `phase` is `'reconnected`, `'resolved'`,
* or `'rejected'`. Its type is `T` for resolutions and `U` for rejections.
*/
readonly payload: T | U | null;

/**
* The current poll phase.
*/
readonly phase: Phase<V>;

/**
* The timestamp for when this tick was scheduled.
*/
readonly timestamp: number;
};
}

/**
* A function whose invocations are rate limited and can be stopped after
* invocation before it has fired.
*
* @typeparam T - The resolved type of the underlying function. Defaults to any.
*
* @typeparam U - The rejected type of the underlying function. Defaults to any.
*/
export interface IRateLimiter<T = any, U = any> extends IDisposable {
/**
* The rate limit in milliseconds.
*/
readonly limit: number;

/**
* Invoke the rate limited function.
*/
invoke(): Promise<T>;

/**
* Stop the function if it is mid-flight.
*/
stop(): Promise<void>;
}

/**
* An interface for a state restorer.
*
Expand Down