package com.test.reactor; import java.util.Date; import reactor.core.publisher.Mono; public class FluxDefer { public static void main(String[] args) { /* Flux.range(1, 10) .timeout(Flux.never(), v -> Flux.never()) .subscribe(System.out::println); System.out.println("-----------------------------------------"); Flux.range(1, 1000).take(10).subscribe(System.out::println); System.out.println("-----------------------------------------"); Flux.range(1, 1000).takeLast(10).subscribe(System.out::println); System.out.println("-----------------------------------------"); Flux.range(1, 1000).takeWhile(i -> i < 10).subscribe(System.out::println); System.out.println("-----------------------------------------"); Flux.range(1, 1000).takeUntil(i -> i == 10).subscribe(System.out::println);*/ Mono<Date> m1 = Mono.just(new Date()); Mono<Date> m2 = Mono.defer(()->Mono.just(new Date())); m1.subscribe(System.out::println); m2.subscribe(System.out::println); //延迟5秒钟 try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } m1.subscribe(System.out::println); m2.subscribe(System.out::println); } }
Wed Nov 18 15:00:16 CST 2020
Wed Nov 18 15:00:16 CST 2020
Wed Nov 18 15:00:16 CST 2020
Wed Nov 18 15:00:21 CST 2020