@@ -203,7 +203,7 @@ public fun <T> Flow<T>.debounce(timeout: (T) -> Duration): Flow<T> =
203
203
timeout(emittedItem).toDelayMillis()
204
204
}
205
205
206
- private fun <T > Flow<T>.debounceInternal (timeoutMillisSelector : (T ) -> Long ) : Flow <T > =
206
+ private fun <T > Flow<T>.debounceInternal (timeoutMillisSelector : (T ) -> Long ): Flow <T > =
207
207
scopedFlow { downstream ->
208
208
// Produce the values using the default (rendezvous) channel
209
209
val values = produce {
@@ -306,7 +306,10 @@ public fun <T> Flow<T>.sample(periodMillis: Long): Flow<T> {
306
306
/*
307
307
* TODO this design (and design of the corresponding operator) depends on #540
308
308
*/
309
- internal fun CoroutineScope.fixedPeriodTicker (delayMillis : Long , initialDelayMillis : Long = delayMillis): ReceiveChannel <Unit > {
309
+ internal fun CoroutineScope.fixedPeriodTicker (
310
+ delayMillis : Long ,
311
+ initialDelayMillis : Long = delayMillis
312
+ ): ReceiveChannel <Unit > {
310
313
require(delayMillis >= 0 ) { " Expected non-negative delay, but has $delayMillis ms" }
311
314
require(initialDelayMillis >= 0 ) { " Expected non-negative initial delay, but has $initialDelayMillis ms" }
312
315
return produce(capacity = 0 ) {
@@ -359,8 +362,15 @@ public fun <T> Flow<T>.sample(period: Duration): Flow<T> = sample(period.toDelay
359
362
* emit(3)
360
363
* delay(1000)
361
364
* emit(4)
362
- * }.timeout(100.milliseconds).catch {
363
- * emit(-1) // Item to emit on timeout
365
+ * }.timeout(100.milliseconds).catch { exception ->
366
+ * if (exception is TimeoutCancellationException) {
367
+ * // Catch the TimeoutCancellationException emitted above.
368
+ * // Emit desired item on timeout.
369
+ * emit(-1)
370
+ * } else {
371
+ * // Throw other exceptions.
372
+ * throw exception
373
+ * }
364
374
* }.onEach {
365
375
* delay(300) // This will not cause a timeout
366
376
* }
0 commit comments