异步转Mono

2024-02-12

java

小利不争,小忿不发,可以合众。——傅昭

今天分享一个异步方法转Mono的方式,利用reactor.core.publisher.Mono#create

1
2
3
4
5
6
7
8
9
10
11
return Mono.create(sink -> rtmClient.subscribe(channelName, options, new ResultCallback<Void>() {
@Override
public void onSuccess(Void unused) {
sink.success(unused);
}

@Override
public void onFailure(ErrorInfo errorInfo) {
sink.error(new IllegalStateException(errorInfo.getErrorReason()));
}
}));

即可实现