David Arce
David Arce

Reputation: 13

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

Upvotes: 1

Views: 2792

Answers (1)

bsideup
bsideup

Reputation: 3063

Consider using Mono#deferWithContext:

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

Upvotes: 5

Related Questions