Java Code Examples for reactor.core.publisher.Flux#delayElements()

The following examples show how to use reactor.core.publisher.Flux#delayElements() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Bean
RouterFunction<ServerResponse> fibonacciEndpoint() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.error(new RuntimeException("out of bound"));
        else
            sink.next(state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });

    Flux<Long> delayedGenerator = fibonacciGenerator.delayElements(Duration.ofSeconds(1));

    RouterFunction<ServerResponse> fibonacciRoute =
            RouterFunctions.route(RequestPredicates.path("/fibonacci"),
                    request ->  ServerResponse.ok()
                                .body(fromPublisher(delayedGenerator, Long.class)));

    return fibonacciRoute;
}
 
Example 2
@Bean
RouterFunction<ServerResponse> fibonacciEndpoint() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.error(new RuntimeException("out of bound"));
        else
            sink.next(state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });

    Flux<Long> delayedGenerator = fibonacciGenerator.delayElements(Duration.ofSeconds(1));

    RouterFunction<ServerResponse> fibonacciRoute =
            RouterFunctions.route(RequestPredicates.path("/fibonacci"),
                    request ->  ServerResponse.ok()
                                .body(fromPublisher(delayedGenerator, Long.class)));

    return fibonacciRoute;
}
 
Example 3
@Bean
RouterFunction<ServerResponse> fibonacciEndpoint() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.error(new RuntimeException("out of bound"));
        else
            sink.next(state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });

    Flux<Long> delayedGenerator = fibonacciGenerator.delayElements(Duration.ofSeconds(1));

    RouterFunction<ServerResponse> fibonacciRoute =
            RouterFunctions.route(RequestPredicates.path("/fibonacci"),
                    request ->  ServerResponse.ok()
                                .body(fromPublisher(delayedGenerator, Long.class)));

    return fibonacciRoute;
}
 
Example 4
@GetMapping(value = "/numbers1", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Long>  handleSeries1() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.complete();
        else
            sink.next(state.getT1());
        System.out.println("numbers1 generated :"+state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });
    return fibonacciGenerator.delayElements(Duration.ofSeconds(1));
}
 
Example 5
@GetMapping(value = "/numbers1", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Long>  handleSeries1() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.complete();
        else
            sink.next(state.getT1());
        System.out.println("numbers1 generated :"+state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });
    return fibonacciGenerator.delayElements(Duration.ofSeconds(1));
}
 
Example 6
@GetMapping(value = "/numbers1", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<Long>  handleSeries1() {
    Flux<Long> fibonacciGenerator = Flux.generate(() -> Tuples.<Long,
            Long>of(0L, 1L), (state, sink) -> {
        if (state.getT1() < 0)
            sink.complete();
        else
            sink.next(state.getT1());
        System.out.println("numbers1 generated :"+state.getT1());
        return Tuples.of(state.getT2(), state.getT1() + state.getT2());
    });
    return fibonacciGenerator.delayElements(Duration.ofSeconds(1));
}