-
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.
- Loading branch information
Elijah Verdoorn
committed
Sep 18, 2019
1 parent
f441eb1
commit 2bf26f6
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package interop.maybe | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.rx2.rxMaybe | ||
import kotlin.coroutines.CoroutineContext | ||
import kotlin.random.Random | ||
|
||
class MaybeInterop( | ||
override val coroutineContext: CoroutineContext = Dispatchers.Default | ||
): CoroutineScope { | ||
fun doWorkMaybe() = CoroutineScope(coroutineContext).rxMaybe { | ||
return@rxMaybe if (Random.Default.nextBoolean()) "A value from the function" else null | ||
} | ||
} |
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.maybe | ||
|
||
fun main() { | ||
println("Creating an instance of MaybeInterop") | ||
val maybeInterop = MaybeInterop() | ||
maybeInterop.doWorkMaybe().subscribe(::println, ::println) | ||
|
||
Thread.sleep(2000) // Sleep the main thread to await the completion of the background thread | ||
} |