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