7
7
package kotlinx.coroutines.reactor
8
8
9
9
import kotlinx.coroutines.*
10
+ import kotlinx.coroutines.reactive.*
10
11
import org.reactivestreams.*
11
12
import reactor.core.*
12
13
import reactor.core.publisher.*
13
14
import kotlin.coroutines.*
14
15
import kotlin.internal.*
15
16
16
17
/* *
17
- * Creates cold [mono][Mono] that runs a given [block] in a coroutine and emits its result.
18
+ * Creates a cold [mono][Mono] that runs a given [block] in a coroutine and emits its result.
18
19
* Every time the returned mono is subscribed, it starts a new coroutine.
19
20
* If the result of [block] is `null`, [MonoSink.success] is invoked without a value.
20
21
* Unsubscribing cancels the running coroutine.
21
22
*
22
23
* Coroutine context can be specified with [context] argument.
23
24
* If the context does not have any dispatcher nor any other [ContinuationInterceptor], then [Dispatchers.Default] is used.
24
25
*
25
- * Method throws [ IllegalArgumentException] if provided [context] contains a [Job] instance.
26
+ * @ throws IllegalArgumentException if the provided [context] contains a [Job] instance.
26
27
*/
27
28
public fun <T > mono (
28
29
context : CoroutineContext = EmptyCoroutineContext ,
@@ -33,22 +34,6 @@ public fun <T> mono(
33
34
return monoInternal(GlobalScope , context, block)
34
35
}
35
36
36
- @Suppress(" UNCHECKED_CAST" )
37
- internal suspend fun <T > Mono<T>.await (): T ? = (this as Mono <T ?>).awaitOrDefault(null )
38
-
39
- internal suspend fun <T > Mono<T>.awaitOrDefault (default : T ): T = suspendCancellableCoroutine { cont ->
40
- subscribe(object : CoreSubscriber <T > {
41
- override fun onSubscribe (s : Subscription ) {
42
- cont.invokeOnCancellation { s.cancel() }
43
- s.request(1 )
44
- }
45
- override fun onNext (t : T ) { cont.resume(t) }
46
- override fun onError (t : Throwable ) { cont.resumeWithException(t) }
47
- override fun onComplete () { cont.resume(default) }
48
-
49
- })
50
- }
51
-
52
37
@Deprecated(
53
38
message = " CoroutineScope.mono is deprecated in favour of top-level mono" ,
54
39
level = DeprecationLevel .ERROR ,
0 commit comments