Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Jul 17, 2019
1 parent 2fa8ee9 commit c2fd09f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
Expand Up @@ -29,7 +29,7 @@ public final class kotlinx/coroutines/reactor/ReactorContext$Key : kotlin/corout
}

public final class kotlinx/coroutines/reactor/ReactorContextKt {
public static final fun asCoroutineContext (Lreactor/util/context/Context;)Lkotlin/coroutines/CoroutineContext;
public static final fun asCoroutineContext (Lreactor/util/context/Context;)Lkotlinx/coroutines/reactor/ReactorContext;
}

public final class kotlinx/coroutines/reactor/SchedulerCoroutineDispatcher : kotlinx/coroutines/CoroutineDispatcher, kotlinx/coroutines/Delay {
Expand Down
2 changes: 1 addition & 1 deletion reactive/kotlinx-coroutines-reactor/src/Flux.kt
Expand Up @@ -74,4 +74,4 @@ private fun <T> reactorPublish(
val coroutine = PublisherCoroutine(newContext, subscriber)
subscriber.onSubscribe(coroutine) // do it first (before starting coroutine), to avoid unnecessary suspensions
coroutine.start(CoroutineStart.DEFAULT, coroutine, block)
}
}
30 changes: 12 additions & 18 deletions reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt
Expand Up @@ -5,33 +5,28 @@ import reactor.util.context.Context
import kotlin.coroutines.*

/**
* Marks coroutine context element that contains Reactor's [Context] elements in [context] for seamless integration
* between [CoroutineContext] and Reactor's [Context].
* Wraps Reactor's [Context] into [CoroutineContext] element for seamless integration Reactor and kotlinx.coroutines.
*
* [Context.asCoroutineContext] is defined to add Reactor's [Context] elements as part of [CoroutineContext].
*
* Reactor builders: [mono], [flux] can extract the reactor context from their coroutine context and
* pass it on. Modifications of reactor context can be retrieved by `coroutineContext[ReactorContext]`.
*
* Example usage:
* Reactor builders [mono] and [flux] use this context element to enhance the resulting `subscriberContext`.
*
* ### Usages
* Passing reactor context from coroutine builder to reactor entity:
*
* ```
* launch(Context.of("key", "value").asCoroutineContext()) {
* mono {
* assertEquals(coroutineContext[ReactorContext]!!.context.get("key"), "value")
* }.subscribe()
* mono {
* println(coroutineContext[ReactorContext]) // Prints { "key": "value" }
* }.subscribe()
* }
* ```
*
* Accessing modified reactor context enriched from downstream via coroutine context:
*
* Accessing modified reactor context enriched from the downstream:
* ```
* launch {
* mono {
* assertEquals(coroutineContext[ReactorContext]!!.context.get("key"), "value")
* }.subscriberContext(Context.of("key", "value"))
* mono {
* println(coroutineContext[ReactorContext]) // Prints { "key": "value" }
* }.subscriberContext(Context.of("key", "value"))
* .subscribe()
* }
* ```
Expand All @@ -41,10 +36,9 @@ public class ReactorContext(val context: Context) : AbstractCoroutineContextElem
companion object Key : CoroutineContext.Key<ReactorContext>
}


/**
* Wraps the given [Context] into [ReactorContext], so it can be added to coroutine's context
* and later retrieved via `coroutineContext[ReactorContext]`.
* and later used via `coroutineContext[ReactorContext]`.
*/
@ExperimentalCoroutinesApi
public fun Context.asCoroutineContext(): CoroutineContext = ReactorContext(this)
public fun Context.asCoroutineContext(): ReactorContext = ReactorContext(this)

0 comments on commit c2fd09f

Please sign in to comment.