5
5
package kotlinx.coroutines.reactor
6
6
7
7
import kotlinx.coroutines.ExperimentalCoroutinesApi
8
- import reactor.util.context.Context
9
8
import kotlin.coroutines.*
10
9
import kotlinx.coroutines.reactive.*
10
+ import reactor.util.context.*
11
11
12
12
/* *
13
13
* Wraps Reactor's [Context] into a [CoroutineContext] element for seamless integration between
@@ -50,12 +50,29 @@ import kotlinx.coroutines.reactive.*
50
50
*/
51
51
@ExperimentalCoroutinesApi
52
52
public class ReactorContext (public val context : Context ) : AbstractCoroutineContextElement(ReactorContext ) {
53
+
54
+ public constructor (contextView: ContextView ): this (Context .of(contextView))
55
+
53
56
public companion object Key : CoroutineContext.Key<ReactorContext>
54
57
}
55
58
56
59
/* *
57
- * Wraps the given [Context] into [ReactorContext], so it can be added to coroutine's context
60
+ * Wraps the given [ContextView] into [ReactorContext], so it can be added to the coroutine's context
61
+ * and later used via `coroutineContext[ReactorContext]`.
62
+ */
63
+ @ExperimentalCoroutinesApi
64
+ public fun ContextView.asCoroutineContext (): ReactorContext = ReactorContext (this )
65
+
66
+ /* *
67
+ * Wraps the given [Context] into [ReactorContext], so it can be added to the coroutine's context
58
68
* and later used via `coroutineContext[ReactorContext]`.
59
69
*/
60
70
@ExperimentalCoroutinesApi
61
- public fun Context.asCoroutineContext (): ReactorContext = ReactorContext (this )
71
+ @Deprecated(" Use the more general version for ContextView instead" , level = DeprecationLevel .HIDDEN )
72
+ public fun Context.asCoroutineContext (): ReactorContext = readOnly().asCoroutineContext()
73
+
74
+ /* *
75
+ * Updates the Reactor context in this [CoroutineContext], adding (or possibly replacing) some values.
76
+ */
77
+ internal fun CoroutineContext.extendReactorContext (extensions : ContextView ): CoroutineContext =
78
+ (this [ReactorContext ]?.context?.putAll(extensions) ? : extensions).asCoroutineContext()
0 commit comments