【发布时间】:2019-12-19 14:37:21
【问题描述】:
我想在流因任何原因(包括取消)终止后最终做点什么,我
找到了doFinally方法,但是取消的时候没用,因为https://github.com/reactor/reactor-core/issues/1090#issuecomment-367633241显示:
取消仅在上游进行
那么,如何捕获取消信号呢?
这是我的代码:
public Mono<Void> myFunction() {
return Mono.just("hello")
.flatMap(s -> foo(s))
.doFinally(signalType -> {
// do something finally, but the doFinally won't be called
System.out.println(signalType);
});
}
// some other library's function that I cant not modify any way
public Mono<Void> foo(String s) {
// return a reactive stream, and will cancel it after it be subscribed, like:
return Mono.just(s)
.doOnSubscribe(subscription -> subscription.cancel())
.then();
}
【问题讨论】:
标签: java spring-webflux project-reactor