Skip to content

Commit bc7d362

Browse files
dkhalanskyjbpablobaxter
authored andcommitted
Fix sample code for ReactorContext (Kotlin#2682)
* Also add toString implementation
1 parent fa7b73f commit bc7d362

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

reactive/kotlinx-coroutines-reactor/api/kotlinx-coroutines-reactor.api

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public final class kotlinx/coroutines/reactor/ReactorContext : kotlin/coroutines
3535
public fun <init> (Lreactor/util/context/Context;)V
3636
public fun <init> (Lreactor/util/context/ContextView;)V
3737
public final fun getContext ()Lreactor/util/context/Context;
38+
public fun toString ()Ljava/lang/String;
3839
}
3940

4041
public final class kotlinx/coroutines/reactor/ReactorContext$Key : kotlin/coroutines/CoroutineContext$Key {

reactive/kotlinx-coroutines-reactor/src/ReactorContext.kt

+5-3
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ import reactor.util.context.*
2727
* ```
2828
* val flux = myDatabaseService.getUsers()
2929
* .contextWrite { ctx -> println(ctx); ctx }
30-
* flux.await() // Will print "null"
30+
* flux.awaitFirst() // Will print "null"
3131
*
3232
* // Now add ReactorContext
3333
* withContext(Context.of("answer", "42").asCoroutineContext()) {
34-
* flux.await() // Will print "Context{'key'='value'}"
34+
* flux.awaitFirst() // Will print "Context{'key'='value'}"
3535
* }
3636
* ```
3737
*
3838
* #### Propagating subscriber's Context to ReactorContext:
3939
* ```
4040
* val flow = flow {
41-
* println("Reactor context in Flow: " + coroutineContext[ReactorContext])
41+
* println("Reactor context in Flow: " + currentCoroutineContext()[ReactorContext])
4242
* }
4343
* // No context
4444
* flow.asFlux()
@@ -55,6 +55,8 @@ public class ReactorContext(public val context: Context) : AbstractCoroutineCont
5555
public constructor(contextView: ContextView): this(Context.of(contextView))
5656

5757
public companion object Key : CoroutineContext.Key<ReactorContext>
58+
59+
override fun toString(): String = context.toString()
5860
}
5961

6062
/**

0 commit comments

Comments
 (0)