简体   繁体   English

如何使用反应器在 doFinally 或 doOnCancel 中获取上下文?

[英]How can I get the context in doFinally or doOnCancel with reactor?

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"));

Consider using Mono#deferWithContext :考虑使用Mono#deferWithContext

return Mono
    .deferWithContext(ctx -> {
        mono.doFinally(signalType -> handleSignal(ctx, signalType))
            .doOnEach(...)
    })
    // later...
    .subscriberContext(ctx -> ctx.put("key", "foo"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM