'How do I insert an action using Context after Mono<Void>?
Mono<Integer> just = Mono.just(1);
Mono<Void> empty = Mono.just(1).flatMap(integer -> {
System.out.println(integer);
return Mono.empty();
});
Mono<Context> contextMono = Mono.subscriberContext().doOnSuccess(context -> {
String aaa = context.get(String.class);
System.out.println(aaa);
});
just.flatMap(integer -> Mono.subscriberContext().map(context -> {
String aaa = context.get(String.class);
System.out.println(aaa);
return integer;
})
).subscriberContext(context -> context.put(String.class, "aaa")).subscribe();
//No Execute
empty.flatMap(unused -> contextMono).subscriberContext(context -> context.put(String.class, "aaa")).subscribe();
//Context is empty
empty.doOnSuccess(unused -> contextMono.block()).subscriberContext(context -> context.put(String.class, "aaa")).subscribe();
//Execute multiple times
empty.then(contextMono).then(empty).subscribe();
How do I add an operation after a mono that uses the data in the context and eventually returns the data from the original mono. It's all well good to use flatmap when mono has a return value, but when monoVoid, I don't know how to do it. How to perform operations that are compatible with elements and Void?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
