Context lost when using await but works with subscribe #1455
-
DescriptionI have a method using an Uni and returning a Multi. But the twist is: I need some data when the Multi is completed, and this data is accessible in the Uni, before I create the Multi. So I'm using a context to store this data and get it back later. private Multi<String> fetch() {
return step1()
.call(step1Result -> step2()
// Store "step2" result in the context
.withContext((s2, ctx) -> s2.invoke(step2Result -> ctx.put("s2", step2Result)))
)
.chain(step1Result -> step3())
.onItem()
.transformToMulti(step3Result -> step4(step3Result))
.withContext((multi, ctx) -> multi
.onCompletion()
.call(() -> {
// I need "step2" result here to do some stuff. When using `subscribe` I have "s2" value in context. When using `await` I don't have it
return Uni.createFrom().voidItem();
})
);
} Actual behaviorWhen I'm using a var results = fetch()
.subscribe()
.asStream()
.toList();
// "s2" value was in the context when the Multi completed: OK var results = fetch()
.collect()
.asList()
.subscribe()
.asCompletionStage()
.join();
// "s2" value was in the context when the Multi completed: OK But when I'm using var results = fetch()
.collect()
.asList()
.await()
.indefinitely();
// "s2" value wasn't in the context when the Multi completed: Failure Expected behaviorI guess the context propagation should work the same way, whether we use AnalysisFrom the
But I don't get why this would have an impact on the context when my multi completes. Reproducerhttps://github.com/jdussouillez/mutiny-context-from-uni-to-multi/tree/master |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You should use What you are observing might be a side effect of what happens when operators check for subscribers context. I'll have a look to see if this is a bug or not 😉 |
Beta Was this translation helpful? Give feedback.
There's a minor bug here, will be tracked in #1457