-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Milestone
Description
We can use setCancellation
for the AsyncEmitter
that we have inside Observable.fromAsync
method. It's very useful because we are able to release something in the case when the subscription was terminated. For example:
Observable.fromAsync(emitter -> {
SomeProtocolClient client = new SomeProtocolClient(getUri());
Callback callback = new Callback() {
@Override
public void onLoad(Response response) {
Model model = parse(response);
emitter.onNext(model);
emitter.onCompleted();
}
@Override
public void onError() {
emitter.onError(new ApiException("No response"));
}
};
Request request = client.get(callback);
emitter.setCancellation(request::cancel); // release some resources, it's useful to have setCalcellation
}, AsyncEmitter.BackpressureMode.BUFFER);
Wouldn't it be nice to have something like that for the Single
and Completable
?