Roman Elizarov | 3258e1f | 2019-08-22 20:08:48 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
| 3 | */ |
| 4 | |
| 5 | // This file was automatically generated from coroutines-guide.md by Knit tool. Do not edit. |
| 6 | package kotlinx.coroutines.guide.flow30 |
| 7 | |
| 8 | import kotlinx.coroutines.* |
| 9 | import kotlinx.coroutines.flow.* |
| 10 | |
| 11 | fun foo(): Flow<Int> = flow { |
| 12 | for (i in 1..3) { |
| 13 | println("Emitting $i") |
| 14 | emit(i) |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | fun main() = runBlocking<Unit> { |
| 19 | foo() |
| 20 | .onEach { value -> |
| 21 | check(value <= 1) { "Collected $value" } |
| 22 | println(value) |
| 23 | } |
| 24 | .catch { e -> println("Caught $e") } |
| 25 | .collect() |
| 26 | } |