package org.javacodegeeks.examples.v3;

import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

import java.time.Duration;

public class PublishOnExample {
    public static void main(String[] args) throws Exception {
        Flux.range(1, 10)
            .map(i -> {
                System.out.printf("[%s] Mapping %s\n", Thread.currentThread().getName(), i);
                return i * 2;
            })
            .publishOn(Schedulers.parallel())
            .filter(i -> {
                System.out.printf("[%s] Filtering %s\n", Thread.currentThread().getName(), i);
                return i >= 10;
            })
            .subscribeOn(Schedulers.boundedElastic())
            .subscribe();

        Thread.sleep(Duration.ofSeconds(10));
    }
}
