SnapshotPoller

@ObjCName(swiftName = "SnapshotPoller")
class SnapshotPoller(backgrounder: BackgroundTaskManager, interval: Duration)

Polls the inspector APIs (BackgroundTaskManager.scheduled / BackgroundTaskManager.diagnostics) on an interval and surfaces the latest snapshot through a StateFlow pair.

Inspector UIs typically want both the event stream (via Monitor) and the current state (the inspector APIs) on a refresh cadence. This helper takes care of the polling loop and back-pressure:

  • One StateFlow<List<ScheduledTask>> reflects the latest scheduled() response.

  • One StateFlow<PlatformDiagnostics> reflects the latest diagnostics() response.

  • The poll coroutine sleeps for interval between polls; intervals shorter than ~250 ms are discouraged (the underlying iOS query is callback-shaped and the Android query reads WorkInfo over an IPC).

Scope ownership. The poller's loop runs on the CoroutineScope passed to start. Cancel the scope to stop polling. The flows continue to hold their last-emitted value indefinitely; consumers reading after cancellation see a frozen view.

Initial state. Before the first successful poll completes, both flows emit null / PlatformDiagnostics.Healthy respectively. After that, every poll either updates the flow value or leaves it unchanged if nothing changed (StateFlow's distinct-equal de-duplication).

Constructors

Link copied to clipboard
constructor(backgrounder: BackgroundTaskManager, interval: Duration)

Properties

Link copied to clipboard
@ObjCName(swiftName = "diagnostics")
val diagnostics: StateFlow<PlatformDiagnostics>

Most recent diagnostics() snapshot. Defaults to PlatformDiagnostics.Healthy until the first poll.

Link copied to clipboard
@ObjCName(swiftName = "scheduled")
val scheduled: StateFlow<List<ScheduledTask>?>

Most recent scheduled() snapshot, or null until the first poll completes. SKIE bridges this as AsyncSequence<[ScheduledTask]?>.

Functions

Link copied to clipboard
@ObjCName(swiftName = "start")
fun start(scope: CoroutineScope): Job

Begin polling on scope. Idempotent — calling twice is treated as a restart on the new scope; the previous loop is cancelled. Returns the Job driving the loop so callers can join or cancel it directly if they prefer.

Link copied to clipboard
@ObjCName(swiftName = "stop")
fun stop()

Stop polling. Idempotent.