'How to create multiple Flux from aysnc callbacks

From Reactor's reference guide, I learnt that Flux.create() can be used to convert aysnc callback to Flux.

However, sometimes callbacks have multiple methods to receive multiple types of data, assume I have piece of code as below:

asrService.recognize(new Callback() {
    @Override
    public void stateChange(State state) {
        // consume state
    }

    @Override
    public void onResultData(Result result) {
        // consume result
    }
});

How to convert it to two reactive streams: Flux<State> and Flux<Result>?



Solution 1:[1]

Just small snippet usable for given task.

Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
Sinks.EmitResult result = sink.tryEmitNext("some string");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1