diff --git a/packages/polling-controller/src/PollingController.ts b/packages/polling-controller/src/PollingController.ts index 9a1f3fa7d91..3760d1b9d01 100644 --- a/packages/polling-controller/src/PollingController.ts +++ b/packages/polling-controller/src/PollingController.ts @@ -9,6 +9,12 @@ export type PollingCompleteType = { payload: [string]; }; +/* + * PollingController is an abstract class that implements the polling + * functionality for a controller. It is meant to be extended by a controller + * that needs to poll for data by networkClientId. + * + */ export default abstract class ControllerPolling< Name extends string, State extends Record, @@ -27,6 +33,12 @@ export default abstract class ControllerPolling< private readonly intervalIds: Record = {}; + /** + * Starts polling for a networkClientId + * + * @param networkClientId - The networkClientId to start polling for + * @returns void + */ start(networkClientId: NetworkClientId) { const innerPollToken = random(); if (this.networkClientIdTokensMap.has(networkClientId)) { @@ -42,6 +54,9 @@ export default abstract class ControllerPolling< return innerPollToken; } + /** + * Stops polling for all networkClientIds + */ stopAll() { this.networkClientIdTokensMap.forEach((tokens, _networkClientId) => { tokens.forEach((token) => { @@ -50,6 +65,11 @@ export default abstract class ControllerPolling< }); } + /** + * Stops polling for a networkClientId + * + * @param pollingToken - The polling token to stop polling for + */ stop(pollingToken: string) { if (!pollingToken) { throw new Error('pollingToken required'); @@ -77,6 +97,11 @@ export default abstract class ControllerPolling< } } + /** + * Executes the poll for a networkClientId + * + * @param networkClientId - The networkClientId to execute the poll for + */ abstract executePoll(networkClientId: NetworkClientId): Promise; #poll(networkClientId: NetworkClientId) {