-
Notifications
You must be signed in to change notification settings - Fork 2
ifOnline block
github-actions[bot] edited this page Jun 2, 2026
·
1 revision
import com.mobilebytelabs.kmptoolkit.networkmonitor.NetworkMonitorProvider
import com.mobilebytelabs.kmptoolkit.networkmonitor.ifOnline
suspend fun syncIfOnline(uploadPayload: suspend () -> Unit) {
val monitor = NetworkMonitorProvider.get()
monitor.ifOnline {
uploadPayload()
}
}For UI threads that should wait for reconnect:
monitor.retryOnReconnect(max = 3) { uploadPayload() }-
ifOnline { }is a one-shot gate — it samplesisOnline.valueat call time and runs the block (or no-ops) without subscribing. For "wait until online then run," usemonitor.ensureOnline()then your block. -
retryOnReconnect()only retries on transitions Unavailable→Available; it does NOT retry on application-level errors thrown by your block. - On
wasmJs, the underlying StateFlow updates only when the browser tab is focused — a backgrounded tab can miss transitions.
- Module: cmp-network-monitor
- Sample:
samples/sample-cmp-network-monitor/composeApp/.../RetryDemo.kt - See also: React to the device going offline for reactive patterns.
** Partials**
App Intents
Bubble
Clipboard
Cookbook
- Clipboard Copy Text
- Clipboard Read Text
- Consumer Anon Key Setup
- Crashlytics Attribution Per Library
- Ifonline Block
- Index
- Index
- Index
- Index
- Open Url Compose
- Pick And Share Image
- React To Offline
- Register Firebase Hooks
- Share Pdf Android
- Share Text
- Wifi Vs Cellular
Firebase Analytics
In App Update
Intent Launcher
Inter App Comms
Modules
- Cmp App Intents
- Cmp App Intents Compose
- Cmp Bubble
- Cmp Clipboard
- Cmp Deep Link
- Cmp Firebase Analytics
- Cmp In App Update
- Cmp Intent Launcher
- Cmp Intent Launcher Compose
- Cmp Library
- Cmp Network Monitor
- Cmp Network Monitor Compose
- Cmp Observe
- Cmp Observe Koin
- Cmp Open Url
- Cmp Pdf Generator
- Cmp Product Tickets
- Cmp Remote Config
- Cmp Share
- Cmp Share Compose
- Cmp Toast
Network Monitor
Open Url
Pdf Generator
Remote Config
Share
Toast
User Tickets
General