1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Mono.empty().subscribe(System.out::println);
Mono.just("www.jackssybin.cn").subscribe(System.out::println);
Mono.justOrEmpty(null).subscribe(System.out::println); Mono.justOrEmpty("jackssy").subscribe(System.out::println); Mono.justOrEmpty(Optional.of("jackssy")).subscribe(System.out::println);
Mono.error(new RuntimeException("error")).subscribe(System.out::println, System.err::println);
Mono.never().subscribe(System.out::println);
Mono.create(sink -> sink.success("jackssy")).subscribe(System.out::println);
Mono.fromRunnable(() -> { System.out.println("thread run"); throw new RuntimeException("thread run error"); }).subscribe(System.out::println, System.err::println);
Mono.fromCallable(() -> "callable run ").subscribe(System.out::println);
Mono.fromSupplier(() -> "create from supplier").subscribe(System.out::println);
long start = System.currentTimeMillis(); Disposable disposable = Mono.delay(Duration.ofSeconds(2)).subscribe(n -> { System.out.println("生产数据源:"+ n); System.out.println("当前线程ID:"+ Thread.currentThread().getId() + ",生产到消费耗时:"+ (System.currentTimeMillis() - start)); }); System.out.println("主线程"+ Thread.currentThread().getId() + "耗时:"+ (System.currentTimeMillis() - start));
while(!disposable.isDisposed()) { }
|