mono.defer
时间: 2023-11-22 18:04:27 浏览: 195
引用\[1\]: Mono.defer JDK注释 Create a Mono provider that will supply a target Mono to subscribe to for each Subscriber downstream. 翻译 。
引用\[2\]:本篇文章分享Mono.just与Mono.defer的区别并用代码进行了测试。 Mono.just JDK注释 Create a new Mono that emits the specified item, which is captured at instantiation time. 翻译 。
引用\[3\]:mono defer方法创建数据源属于懒汉型,与Mono.just等创建数据源则是恶汉型,下面看一个例子: @Test public void defer(){ //声明阶段创建DeferClass对象 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); } 。 问题:mono.defer
回答: mono.defer是一个方法,用于创建一个懒汉型的数据源。与Mono.just等创建数据源不同,Mono.defer在订阅时才会创建目标Mono供下游的Subscriber订阅。\[1\] Mono.just则在实例化时就捕获了指定的项,并创建了一个新的Mono。\[2\] 在给出的例子中,m1是使用Mono.just创建的,而m2是使用Mono.defer创建的。在订阅之前,m1已经发出了一个Date对象,而m2在订阅时才会创建并发出一个新的Date对象。\[3\]
#### 引用[.reference_title]
- *1* *2* [3. Mono.defer 与 Mono.just 区别](https://blog.csdn.net/dydyswr/article/details/126681647)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [反应式编程之Mono.defer](https://blog.csdn.net/john1337/article/details/104205774)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文