Skip to content

Commit

Permalink
Add sample of Observable interoperability
Browse files Browse the repository at this point in the history
  • Loading branch information
Elijah Verdoorn committed Sep 18, 2019
1 parent 2bf26f6 commit c5d6dfc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/kotlin/interop/observable/ObservableInterop.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package interop.observable

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.rx2.rxObservable
import kotlin.coroutines.CoroutineContext

class ObservableInterop(
override val coroutineContext: CoroutineContext = Dispatchers.Default
): CoroutineScope {
fun getStream() = CoroutineScope(coroutineContext).rxObservable {
(1..10).map {
delay(100)
send(it)
}
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/interop/observable/TestObservableInterop.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package interop.observable

fun main() {
println("Creating ObservableInterop")
val observableInterop = ObservableInterop()
observableInterop.getStream().subscribe(::println, ::println)

Thread.sleep(2000)
}

0 comments on commit c5d6dfc

Please sign in to comment.