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

The following examples show how to use reactor.core.publisher.Flux#delayElements() . 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
Source File: FibonacciConfigurer.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 6 votes vote down vote up
@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
Source File: FibonacciConfigurer.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 6 votes vote down vote up
@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
Source File: FibonacciConfigurer.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 6 votes vote down vote up
@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
Source File: ReactiveController.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
@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
Source File: ReactiveController.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
@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
Source File: ReactiveController.java    From Hands-On-Reactive-Programming-with-Reactor with MIT License 5 votes vote down vote up
@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));
}