PollingManager
Defined in: packages/core/src/data/polling-manager.ts:122
Manages polling intervals for data refresh.
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”const polling = new PollingManager();
// Start pollingpolling.start('data-refresh', { interval: 10000, onTick: async () => { await fetchAndUpdateData(); }, immediate: true,});
// Pause temporarilypolling.pause('data-refresh');
// Resumepolling.resume('data-refresh');
// Trigger immediatelyawait polling.triggerNow('data-refresh');
// Stop completelypolling.stop('data-refresh');Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PollingManager():
PollingManager
Defined in: packages/core/src/data/polling-manager.ts:126
Returns
Section titled “Returns”PollingManager
Methods
Section titled “Methods”destroy()
Section titled “destroy()”destroy():
void
Defined in: packages/core/src/data/polling-manager.ts:413
Clean up all resources and stop all polling.
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”Should be called when the polling manager is no longer needed. After calling destroy, the polling manager should not be used.
Example
Section titled “Example”polling.destroy();getActiveIds()
Section titled “getActiveIds()”getActiveIds():
string[]
Defined in: packages/core/src/data/polling-manager.ts:342
Get all active polling subscription IDs.
Returns
Section titled “Returns”string[]
Array of subscription IDs
Example
Section titled “Example”const ids = polling.getActiveIds();console.log(`Active pollers: ${ids.join(', ')}`);getState()
Section titled “getState()”getState(
id):PollingState|null
Defined in: packages/core/src/data/polling-manager.ts:326
Get the current state of a polling subscription.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”PollingState | null
Current state or null if not found
Example
Section titled “Example”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”boolean
True if the subscription exists
Example
Section titled “Example”if (polling.has('layer-1')) { polling.pause('layer-1');}pause()
Section titled “pause()”pause(
id):void
Defined in: packages/core/src/data/polling-manager.ts:227
Pause a polling subscription without stopping it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”void
Remarks
Section titled “Remarks”Paused subscriptions can be resumed with resume. The subscription maintains its state while paused.
Example
Section titled “Example”polling.pause('layer-1');pauseAll()
Section titled “pauseAll()”pauseAll():
void
Defined in: packages/core/src/data/polling-manager.ts:248
Pause all active polling subscriptions.
Returns
Section titled “Returns”void
Example
Section titled “Example”polling.pauseAll();resume()
Section titled “resume()”resume(
id):void
Defined in: packages/core/src/data/polling-manager.ts:264
Resume a paused polling subscription.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”void
Example
Section titled “Example”polling.resume('layer-1');resumeAll()
Section titled “resumeAll()”resumeAll():
void
Defined in: packages/core/src/data/polling-manager.ts:281
Resume all paused polling subscriptions.
Returns
Section titled “Returns”void
Example
Section titled “Example”polling.resumeAll();setInterval()
Section titled “setInterval()”setInterval(
id,interval):void
Defined in: packages/core/src/data/polling-manager.ts:378
Update the interval for an active polling subscription.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
interval | number | New interval in milliseconds (minimum 1000ms) |
Returns
Section titled “Returns”void
Throws
Section titled “Throws”Error if the subscription doesn’t exist
Remarks
Section titled “Remarks”The new interval takes effect after the current tick completes.
Example
Section titled “Example”polling.setInterval('layer-1', 10000);start()
Section titled “start()”start(
id,config):void
Defined in: packages/core/src/data/polling-manager.ts:147
Start a new polling subscription.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Unique identifier for the subscription |
config | PollingConfig | Polling configuration |
Returns
Section titled “Returns”void
Throws
Section titled “Throws”Error if a subscription with the same ID already exists
Example
Section titled “Example”polling.start('layer-1', { interval: 5000, onTick: async () => { await updateLayerData(); },});stop()
Section titled “stop()”stop(
id):void
Defined in: packages/core/src/data/polling-manager.ts:187
Stop a polling subscription and clean up resources.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”void
Example
Section titled “Example”polling.stop('layer-1');stopAll()
Section titled “stopAll()”stopAll():
void
Defined in: packages/core/src/data/polling-manager.ts:207
Stop all polling subscriptions.
Returns
Section titled “Returns”void
Example
Section titled “Example”polling.stopAll();triggerNow()
Section titled “triggerNow()”triggerNow(
id):Promise<void>
Defined in: packages/core/src/data/polling-manager.ts:303
Trigger an immediate execution of the polling tick.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
id | string | Subscription identifier |
Returns
Section titled “Returns”Promise<void>
Promise that resolves when the tick completes
Throws
Section titled “Throws”Error if the subscription doesn’t exist
Remarks
Section titled “Remarks”This does not affect the regular polling schedule. The next scheduled tick will still occur at the expected time.
Example
Section titled “Example”await polling.triggerNow('layer-1');