Roman Elizarov | 8a4a8e1 | 2017-03-09 19:52:58 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | 8a4a8e1 | 2017-03-09 19:52:58 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | // This file was automatically generated from coroutines-guide-reactive.md by Knit tool. Do not edit. |
Roman Elizarov | a9687a3 | 2018-06-29 17:28:38 +0300 | [diff] [blame] | 6 | package kotlinx.coroutines.experimental.rx2.guide.context01 |
Roman Elizarov | 8a4a8e1 | 2017-03-09 19:52:58 +0300 | [diff] [blame] | 7 | |
Roman Elizarov | 95981f3 | 2017-03-17 18:12:04 +0300 | [diff] [blame] | 8 | import io.reactivex.* |
Roman Elizarov | 8a4a8e1 | 2017-03-09 19:52:58 +0300 | [diff] [blame] | 9 | import io.reactivex.functions.BiFunction |
| 10 | import io.reactivex.schedulers.Schedulers |
| 11 | import java.util.concurrent.TimeUnit |
| 12 | |
| 13 | fun rangeWithIntervalRx(scheduler: Scheduler, time: Long, start: Int, count: Int): Flowable<Int> = |
| 14 | Flowable.zip( |
| 15 | Flowable.range(start, count), |
| 16 | Flowable.interval(time, TimeUnit.MILLISECONDS, scheduler), |
| 17 | BiFunction { x, _ -> x }) |
| 18 | |
| 19 | fun main(args: Array<String>) { |
Roman Elizarov | 86349be | 2017-03-17 16:47:37 +0300 | [diff] [blame] | 20 | rangeWithIntervalRx(Schedulers.computation(), 100, 1, 3) |
| 21 | .subscribe { println("$it on thread ${Thread.currentThread().name}") } |
Roman Elizarov | 8a4a8e1 | 2017-03-09 19:52:58 +0300 | [diff] [blame] | 22 | Thread.sleep(1000) |
| 23 | } |