1 /*
<lambda>null2 * 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-reactive.md by Knit tool. Do not edit.
6 package kotlinx.coroutines.rx2.guide.context05
7
8 import io.reactivex.*
9 import kotlinx.coroutines.*
10 import kotlinx.coroutines.reactive.*
11 import io.reactivex.functions.BiFunction
12 import io.reactivex.schedulers.Schedulers
13 import java.util.concurrent.TimeUnit
14
15 fun rangeWithIntervalRx(scheduler: Scheduler, time: Long, start: Int, count: Int): Flowable<Int> =
16 Flowable.zip(
17 Flowable.range(start, count),
18 Flowable.interval(time, TimeUnit.MILLISECONDS, scheduler),
19 BiFunction { x, _ -> x })
20
<lambda>null21 fun main() = runBlocking<Unit> {
22 val job = launch(Dispatchers.Unconfined) { // launch a new coroutine in Unconfined context (without its own thread pool)
23 rangeWithIntervalRx(Schedulers.computation(), 100, 1, 3)
24 .collect { println("$it on thread ${Thread.currentThread().name}") }
25 }
26 job.join() // wait for our coroutine to complete
27 }
28