Difference Between Flux.create and Flux.generate

前端 未结 2 691
醉话见心
醉话见心 2021-01-31 19:30

What is the difference between Flux.create and Flux.generate? I am looking--ideally with an example use case--to understand when I should use one or the other.

2条回答
  •  梦谈多话
    2021-01-31 19:45

    Create

    • Accepts a Consumer>
    • Consumer is invoked only once per subscriber
    • Consumer can emit 0..N elements immediately
    • Publisher is not aware of downstream state. So we need to provide Overflow strategy as an additional parameter
    • We can get the reference of FluxSink using which we could keep on emitting elements as and when required using multiple threads.

    Generate:

    • Accepts a Consumer>
    • Consumer is invoked again and again based on the downstream demand
    • Consumer can emit only one element at the max with an optional complete/error signal.
    • Publisher produces elements based on the downstream demand
    • We can get the reference of SynchronousSink. But it might not be really useful as we could emit only one element

    Check this blog for more details.

提交回复
热议问题