FlowPollingManager
Declaration
class FlowPollingManager<T>Summary
Manages Flow-based polling for session updates with automatic subscriber tracking and frame deduplication. This class abstracts the common pattern of:
- Creating a MutableSharedFlow
- Tracking active subscribers
- Starting/stopping polling coroutines based on subscriber count
- Deduplicating updates by frame ID or timestamp
Constructors
constructor(pollingIntervalMs: Long, pollFunction: () -> T, frameIdExtractor: ((T) -> Long)? = null, timestampExtractor: ((T) -> Long)? = null)
Parameters
| Name | Type | Summary |
|---|---|---|
| pollingIntervalMs | Long | - |
| pollFunction | () -> T | - |
| frameIdExtractor | ((T) -> Long)? | - |
| timestampExtractor | ((T) -> Long)? | - |
Properties
| Name | Type | Summary |
|---|---|---|
| flow | Flow<T> | Public Flow that automatically manages polling lifecycle. Polls on [Dispatchers.Default] while at least one collector is subscribed; each collector receives values in its own coroutine context. A session's flows can be collected before the session is acquired and across close()/acquire(): they emit only while it is acquired. After [destroy] (when the NSDKSession is closed) every collection completes, and a new one completes at once. |
Functions
| Name | Type | Summary |
|---|---|---|
| createForNSDKResult | FlowPollingManager<NSDKResult<T, E>> | Creates a FlowPollingManager specifically for ARDKResult types, reducing boilerplate code. This helper automatically handles ARDKResult.Success and ARDKResult.Error cases: - Success results are deduplicated based on frameIdExtractor - Error results are emitted when they differ from the previous result, so a change from one error to another is reported, but the same error is not repeated on every poll |
| destroy | void | Ends polling for good and completes every collection of [flow], current and future. Called when the NSDKSession is closed, after which the feature can never emit again; a collector that outlives the session then finishes instead of waiting forever. Waits for a poll in flight. |