An alias of SMono.fromPublisher
An alias of SMono.fromPublisher
Creates a deferred emitter that can be used with callback-based APIs to signal at most one value, a complete or an error signal.
Creates a deferred emitter that can be used with callback-based APIs to signal at most one value, a complete or an error signal.
Bridging legacy API involves mostly boilerplate code due to the lack of standard types and methods. There are two kinds of API surfaces: 1) addListener/removeListener and 2) callback-handler.
1) addListener/removeListener pairs
To work with such API one has to instantiate the listener,
call the sink from the listener then register it with the source:
SMono.<String>create(sink => {
HttpListener listener = event => {
if (event.getResponseCode() >= 400) {
sink.error(new RuntimeException("Failed"));
} else {
String body = event.getBody();
if (body.isEmpty()) {
sink.success();
} else {
sink.success(body.toLowerCase());
}
}
};
client.addListener(listener);
sink.onDispose(() => client.removeListener(listener));
});
Note that this works only with single-value emitting listeners. Otherwise,
all subsequent signals are dropped. You may have to add client.removeListener(this);
to the listener's body.2) callback handler
This requires a similar instantiation pattern such as above, but usually the
successful completion and error are separated into different methods.
In addition, the legacy API may or may not support some cancellation mechanism.
SMono.<String>create(sink => {
Callback<String> callback = new Callback<String>() {
@Override
public void onResult(String data) {
sink.success(data.toLowerCase());
}
@Override
public void onError(Exception e) {
sink.error(e);
}
}
// without cancellation support:
client.call("query", callback);
// with cancellation support:
AutoCloseable cancel = client.call("query", callback);
sink.onDispose(() => {
try {
cancel.close();
} catch (Exception ex) {
Exceptions.onErrorDropped(ex);
}
});
});
The type of the value emitted
Consume the { @link MonoSink} provided per-subscriber by Reactor to generate signals.
a SMono
Pick the first result coming from any of the given monos and populate a new Mono
.
Pick the first result coming from any of the given monos and populate a new Mono
.
The type of the function result.
The deferred monos to use.
a SMono.
Transform a Try into an SMono
Create a SMono emitting the Context available on subscribe.
Aggregate given publishers into a new Mono
that will be fulfilled
when all of the given sources
have been fulfilled.
Aggregate given void publishers into a new a Mono
that will be
fulfilled when all of the given Monos
have been fulfilled.
Aggregate given void publishers into a new a Mono
that will be
fulfilled when all of the given Monos
have been fulfilled. If any Mono terminates without value,
the returned sequence will be terminated immediately and pending results cancelled.
The sources to use.
a SMono.
Aggregate given publishers into a new SMono that will be
fulfilled when all of the given sources
have completed.
Aggregate given publishers into a new SMono that will be
fulfilled when all of the given sources
have completed. If any Publisher
terminates without value, the returned sequence will be terminated immediately and
pending results cancelled. Errors from the sources are delayed.
If several Publishers error, the exceptions are combined (as suppressed exceptions on a root exception).
The sources to use.
a SMono.