-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eager unsubscribe for Observable.using? #2492
Comments
If you have access to the resource outside the factory function, you could call |
Not really. There's no mention of the resource outside of using, and that
|
Actually I think you are on to it. I'll just adjust the resource factory
|
After looking at the options I think the best way is to use If one is able to adjust the resource factory function (and it won't always be the case when using a third party method) then using
public final class OperatorUnsubscribeEagerly<T> implements Operator<T, T> {
@Override
public Subscriber<? super T> call(final Subscriber<? super T> child) {
Subscriber<T> parent = new Subscriber<T>() {
@Override
public void onCompleted() {
unsubscribe();
child.onCompleted();
}
@Override
public void onError(Throwable e) {
unsubscribe();
child.onError(e);
}
@Override
public void onNext(T t) {
child.onNext(t);
}
};
child.add(parent);
return parent;
} Is this a reasonable addition to the Observable API? Might be used like this: Observable.using(...).toUnsubscribeEagerly() |
|
Closed via PR #2759 |
When using
Observable.using
to read from a file (a synchronous source) I want to complete the process by writing back to the same file. Becauseusing
doesn't dispose its resource till the downstream is complete I can't perform my secondary action (unless I block or introduce asynchronicity). I'm wondering about creating anOperator
sayOperatorUnsubscribeEagerly
that could be chained with theusing
command to enable my use case.For example:
An alternative would be an overload on
using
with an additional boolean parameterunsubscribeEagerly
.What do people think? Perhaps I'm overlooking an existing idiom?
The text was updated successfully, but these errors were encountered: