官术网_书友最值得收藏!

The Mono reactive type

 

A Reactive Streams Publisher with basic Rx operators that completes successfully by emitting an element, or with an error.
– Mono JavaDoc

Mono<T> is a Publisher<T> that supports 0..1 elements.

The definition of Mono is as follows:

public abstract class Mono<T>
extends Object
implements Publisher<T>

As detailed in the documentation, the following figure shows the workings of Mono:

Figure 08: Working of Mono

Mono<Void> should be used for a Publisher that completes with no value. The documentation explains each method and how it works using a marble diagram, which is self-explanatory. Again, this type is also supported by Spring 5 and Spring Security.

JavaDoc for Mono contains more information: https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html.

Let's have a look at some examples:

  • Creating empty Mono:
Mono<String> emptyMono = Mono.empty();
  • Creating Mono with a value in it:
Mono<String> itemMono = Mono.just("Spring Security Reactive”);
  • Creating Mono that emits an exception:
Mono.error(new CreatedException());
主站蜘蛛池模板: 定南县| 广元市| 余姚市| 新宁县| 大方县| 阜阳市| 宝鸡市| 佛山市| 青浦区| 五峰| 汤阴县| 任丘市| 康马县| 任丘市| 石景山区| 绥化市| 仙桃市| 长顺县| 环江| 多伦县| 安新县| 上虞市| 托里县| 拉孜县| 民丰县| 醴陵市| 鹤壁市| 晋城| 湛江市| 杂多县| 两当县| 靖边县| 葫芦岛市| 城口县| 台东县| 新绛县| 临清市| 如皋市| 林甸县| 平顶山市| 河间市|