fix: address PR review comments for Kotlin/Android/KMP docs

This commit is contained in:
ali
2026-03-06 23:17:01 +01:00
committed by Affaan Mustafa
parent f10d638bfa
commit 8961f24821
6 changed files with 40 additions and 21 deletions

View File

@@ -125,8 +125,13 @@ searchQuery
// Retry with exponential backoff
fun fetchWithRetry(): Flow<Data> = flow { emit(api.fetch()) }
.retry(3) { cause ->
cause is IOException && run { delay(1000L * (1 shl (3 - remainingAttempts))) ; true }
.retryWhen { cause, attempt ->
if (cause is IOException && attempt < 3) {
delay(1000L * (1 shl attempt.toInt()))
true
} else {
false
}
}
```
@@ -183,7 +188,7 @@ In KMP, use `Dispatchers.Default` and `Dispatchers.Main` (available on all platf
Long-running loops must check for cancellation:
```kotlin
suspend fun processItems(items: List<Item>) {
suspend fun processItems(items: List<Item>) = coroutineScope {
for (item in items) {
ensureActive() // throws CancellationException if cancelled
process(item)