【问题标题】:Flux doesn't emit elmentsFlux 不发射元素
【发布时间】:2019-03-04 04:46:46
【问题描述】:

我在玩 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"));

当我运行代码时,我会看到无数行显示 “在 main 上得到 0”

【问题讨论】:

    标签: flux project-reactor


    【解决方案1】:

    你有 Long 溢出。将您的 while 块更改为

    while (!e.isCancelled()) {
        if (current < 0) {
            e.complete();
        } else {
            e.next(current);
            current *= 2;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-05
      • 2020-10-16
      相关资源
      最近更新 更多