-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sample for converting coroutine to RxJava 2 Completable
- Loading branch information
Elijah Verdoorn
committed
Sep 18, 2019
1 parent
2d95c22
commit f441eb1
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,17 @@ | ||
package interop.completable | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.rx2.rxCompletable | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
class CompletableInterop( | ||
override val coroutineContext: CoroutineContext = Dispatchers.Default | ||
): CoroutineScope { | ||
fun doWork() = CoroutineScope(coroutineContext).rxCompletable { | ||
delay(1000) | ||
println("Hello from the coroutine!") | ||
} | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/interop/completable/TestCompletableInterop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package interop.completable | ||
|
||
fun main() { | ||
println("Creating an instance of CompletableInterop") | ||
val completableInterop = CompletableInterop() | ||
completableInterop.doWork().subscribe() | ||
|
||
Thread.sleep(2000) // Sleep the main thread to await the completion of the background thread | ||
} |