• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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-reactive.md by Knit tool. Do not edit.
6 package kotlinx.coroutines.rx2.guide.context03
7 
8 import io.reactivex.*
9 import kotlinx.coroutines.*
10 import kotlinx.coroutines.reactive.*
11 import io.reactivex.schedulers.Schedulers
12 import kotlin.coroutines.CoroutineContext
13 
<lambda>null14 fun rangeWithInterval(context: CoroutineContext, time: Long, start: Int, count: Int) = publish<Int>(context) {
15     for (x in start until start + count) {
16         delay(time) // wait before sending each number
17         send(x)
18     }
19 }
20 
mainnull21 fun main() {
22     Flowable.fromPublisher(rangeWithInterval(Dispatchers.Default, 100, 1, 3))
23         .observeOn(Schedulers.computation())                           // <-- THIS LINE IS ADDED
24         .subscribe { println("$it on thread ${Thread.currentThread().name}") }
25     Thread.sleep(1000)
26 }
27