Skip to content

PollingManager

Defined in: packages/core/src/data/polling-manager.ts:122

Manages polling intervals for data refresh.

Features:

  • Independent intervals per subscription
  • Visibility-aware (pause when tab hidden)
  • Tracks tick count and error count
  • Non-overlapping execution (waits for tick to complete)
  • Pause/resume functionality
  • Manual trigger support

The polling manager automatically pauses polling when the document becomes hidden (unless pauseWhenHidden is false) and resumes when visible again.

const polling = new PollingManager();
// Start polling
polling.start('data-refresh', {
interval: 10000,
onTick: async () => {
await fetchAndUpdateData();
},
immediate: true,
});
// Pause temporarily
polling.pause('data-refresh');
// Resume
polling.resume('data-refresh');
// Trigger immediately
await polling.triggerNow('data-refresh');
// Stop completely
polling.stop('data-refresh');

new PollingManager(): PollingManager

Defined in: packages/core/src/data/polling-manager.ts:126

PollingManager

destroy(): void

Defined in: packages/core/src/data/polling-manager.ts:413

Clean up all resources and stop all polling.

void

Should be called when the polling manager is no longer needed. After calling destroy, the polling manager should not be used.

polling.destroy();

getActiveIds(): string[]

Defined in: packages/core/src/data/polling-manager.ts:342

Get all active polling subscription IDs.

string[]

Array of subscription IDs

const ids = polling.getActiveIds();
console.log(`Active pollers: ${ids.join(', ')}`);

getState(id): PollingState | null

Defined in: packages/core/src/data/polling-manager.ts:326

Get the current state of a polling subscription.

ParameterTypeDescription
idstringSubscription identifier

PollingState | null

Current state or null if not found

const state = polling.getState('layer-1');
if (state) {
console.log(`Ticks: ${state.tickCount}, Errors: ${state.errorCount}`);
}

has(id): boolean

Defined in: packages/core/src/data/polling-manager.ts:359

Check if a polling subscription exists.

ParameterTypeDescription
idstringSubscription identifier

boolean

True if the subscription exists

if (polling.has('layer-1')) {
polling.pause('layer-1');
}

pause(id): void

Defined in: packages/core/src/data/polling-manager.ts:227

Pause a polling subscription without stopping it.

ParameterTypeDescription
idstringSubscription identifier

void

Paused subscriptions can be resumed with resume. The subscription maintains its state while paused.

polling.pause('layer-1');

pauseAll(): void

Defined in: packages/core/src/data/polling-manager.ts:248

Pause all active polling subscriptions.

void

polling.pauseAll();

resume(id): void

Defined in: packages/core/src/data/polling-manager.ts:264

Resume a paused polling subscription.

ParameterTypeDescription
idstringSubscription identifier

void

polling.resume('layer-1');

resumeAll(): void

Defined in: packages/core/src/data/polling-manager.ts:281

Resume all paused polling subscriptions.

void

polling.resumeAll();

setInterval(id, interval): void

Defined in: packages/core/src/data/polling-manager.ts:378

Update the interval for an active polling subscription.

ParameterTypeDescription
idstringSubscription identifier
intervalnumberNew interval in milliseconds (minimum 1000ms)

void

Error if the subscription doesn’t exist

The new interval takes effect after the current tick completes.

polling.setInterval('layer-1', 10000);

start(id, config): void

Defined in: packages/core/src/data/polling-manager.ts:147

Start a new polling subscription.

ParameterTypeDescription
idstringUnique identifier for the subscription
configPollingConfigPolling configuration

void

Error if a subscription with the same ID already exists

polling.start('layer-1', {
interval: 5000,
onTick: async () => {
await updateLayerData();
},
});

stop(id): void

Defined in: packages/core/src/data/polling-manager.ts:187

Stop a polling subscription and clean up resources.

ParameterTypeDescription
idstringSubscription identifier

void

polling.stop('layer-1');

stopAll(): void

Defined in: packages/core/src/data/polling-manager.ts:207

Stop all polling subscriptions.

void

polling.stopAll();

triggerNow(id): Promise<void>

Defined in: packages/core/src/data/polling-manager.ts:303

Trigger an immediate execution of the polling tick.

ParameterTypeDescription
idstringSubscription identifier

Promise<void>

Promise that resolves when the tick completes

Error if the subscription doesn’t exist

This does not affect the regular polling schedule. The next scheduled tick will still occur at the expected time.

await polling.triggerNow('layer-1');