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
Source Project: Hands-On-Reactive-Programming-with-Reactor File: FibonacciConfigurer.java License: MIT License | 6 votes |
@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 Project: Hands-On-Reactive-Programming-with-Reactor File: FibonacciConfigurer.java License: MIT License | 6 votes |
@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 Project: Hands-On-Reactive-Programming-with-Reactor File: FibonacciConfigurer.java License: MIT License | 6 votes |
@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 Project: Hands-On-Reactive-Programming-with-Reactor File: ReactiveController.java License: MIT License | 5 votes |
@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 Project: Hands-On-Reactive-Programming-with-Reactor File: ReactiveController.java License: MIT License | 5 votes |
@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 Project: Hands-On-Reactive-Programming-with-Reactor File: ReactiveController.java License: MIT License | 5 votes |
@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)); }