英文:
How can I get the context in doFinally or doOnCancel with reactor?
问题
我正在尝试获取上下文中的一个值,我无法弄清楚如何做到这一点,有任何想法吗?示例:
return mono
.doFinally(signalType -> 如何??? )
.doOnEach(signal -> {
... signal.getContext();
...
}) -> 好的,我获取到上下文了
.subscriberContext(ctx -> ctx.put("key", "foo"));
英文:
I'm trying to get a value that I have in the context, I canot figure out how can I do that, any idea?, example:
return mono
.doFinally(signalType -> how??? )
.doOnEach(signal -> { 
... signal.getContext();
...
}) -> is ok I got the context
.subscriberContext(ctx -> ctx.put("key", "foo"));
答案1
得分: 4
考虑使用 Mono#deferWithContext
:
return Mono
.deferWithContext(ctx -> {
mono.doFinally(signalType -> handleSignal(ctx, signalType))
.doOnEach(...)
})
// 后续操作...
.subscriberContext(ctx -> ctx.put("key", "foo"));
英文:
Consider using Mono#deferWithContext
:
return Mono
.deferWithContext(ctx -> {
mono.doFinally(signalType -> handleSignal(ctx, signalType))
.doOnEach(...)
})
// later...
.subscriberContext(ctx -> ctx.put("key", "foo"));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论