我在玩Reactor的磁通API。我已经熟悉RxJava,所以我想测试Reactor的Flux。 我不明白为什么在以下代码中总是收到0:
Flux.create(e -> {
long current = 1;
while (!e.isCancelled()) {
e.next(current);
current *= 2;
}
})
.subscribe(l -> System.out.println("Got " + l + " on " + Thread.currentThread().getName()), e -> System.out.println(e.getMessage() + "!!!!"), () -> System.out.println("finished"));
运行代码时,出现无限行显示 “在主目录上获得0”
答案 0 :(得分:0)
您有长时间溢出。将您的while块更改为
while (!e.isCancelled()) {
if (current < 0) {
e.complete();
} else {
e.next(current);
current *= 2;
}
}