为了账号安全,请及时绑定邮箱和手机立即绑定

FluxProcessor:检索订阅时最后发出的值,如 rx 的主题

FluxProcessor:检索订阅时最后发出的值,如 rx 的主题

慕仙森 2023-10-13 09:52:26
目前,FluxProcessor订阅仅检索订阅后发出的那些值。但我想在订阅时检索 Flux 中的最后一个值,例如,就像 RXSubject所做的那样。我有这个设置:FluxProcessor<Integer, Integer> processor = DirectProcessor.<Integer>create().serialize();FluxSink<Integer> sink = processor.sink();sink.next(1);stateProcessor.subscribe(System.out:println);sink.next(2);输出是:1期望的输出:12
查看完整描述

1 回答

?
月关宝盒

TA贡献1772条经验 获得超5个赞

使用修复它ReplayProcessor。它能够存储 N 个最后发出的值以供进一步订阅。对于同一个例子:


FluxProcessor<Integer, Integer> processor = ReplayProcessor.<Integer>create(1).serialize(); //1 is the history size

FluxSink<Integer> sink = processor.sink();


sink.next(1);


stateProcessor.subscribe(System.out:println);


sink.next(2);

印刷:


1

2


查看完整回答
反对 回复 2023-10-13
  • 1 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信