AccountEventQueue

class AccountEventQueue(maxQueueSize: Int = 200, flushSizeThreshold: Int = 20, flushIntervalMillis: Long, flushHandler: suspend (List<AccountEventsRequests.Event>) -> Pair<RecordResponse?, NetworkingError?> = { events -> AccountEventsAPI.record(events) })

Buffers account/diagnostic events and flushes them to the backend in batches.

Telemetry must never affect a payment flow: every method here is fire-and-forget and every failure — a full queue, a transport error, a per-event rejection — is swallowed. Nothing this type does can throw to, or block, a caller.

In-memory only, by design: there is no disk persistence, so events still queued when the process dies are lost. A flush started from handleAppBackgrounded is best-effort — a POST begun at that point races process death and may never complete.

flushHandler is the seam for testing against a non-prod backend: the queue itself never reads networking constants, so a test supplies its own handler instead of the production AccountEventsAPI.record default.

Constructors

Link copied to clipboard
constructor(maxQueueSize: Int = 200, flushSizeThreshold: Int = 20, flushIntervalMillis: Long, flushHandler: suspend (List<AccountEventsRequests.Event>) -> Pair<RecordResponse?, NetworkingError?> = { events -> AccountEventsAPI.record(events) })

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard

Queues an event, flushing immediately once the size threshold is reached.

Link copied to clipboard
suspend fun flush()

Flushes immediately rather than waiting for flushSizeThreshold or the interval timer.

Link copied to clipboard
suspend fun handleAppBackgrounded()

Best-effort flush when the app goes to the background. Not guaranteed delivery — see the type documentation.

Link copied to clipboard

Test-only inspection of what is currently queued, without triggering a flush.

Link copied to clipboard

Starts the size/time-based flush and app-backgrounding observers. Safe to call more than once, and safe to call from any thread: Lifecycle.addObserver requires the main thread, so registration is dispatched there rather than trusting every caller (this is invoked from com.framepayments.framesdk.FrameNetworking.initializeWithAPIKey, a plain function a host could call from a background thread).