Retrofit: How can I cancel the request with Rxjava2

Created on 6 Jan 2017  Â·  5Comments  Â·  Source: square/retrofit

Most helpful comment

Unsubscribe from the Observable.

All 5 comments

Unsubscribe from the Observable.

@JakeWharton rxjava2 only Disposable,but call dispose() cannet cancel request

Yeah that's what I meant. Dispose is hooked up to Call.cancel().

On Thu, Jan 5, 2017 at 10:04 PM ZzjBeatYou notifications@github.com wrote:

@JakeWharton https://github.com/JakeWharton rxjava2 only Disposable,but
call dispose() cannet cancel request

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/square/retrofit/issues/2147#issuecomment-270820378,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAEEEUiAIQTeb4dZMzf40J7rSCLqWkC-ks5rPa8ngaJpZM4LcWTf
.

thanks

In rxjava2,It could be cancel after using dispose().But I can not subscribe again.
Retrun:HTTP FAILED: java.io.IOException: Canceled.

    private final CompositeDisposable disposables;

 public void execute(DisposableObserver<T> observer) {
        Preconditions.checkNotNull(observer);
        final Observable<T> observable = this.buildUseCaseObservable()
                .throttleFirst(500, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.from(threadExecutor))
                .observeOn(postExecutionThread.getScheduler())
                .compose(getUseCaseTransformer())
                .compose(getCycleTransformer());
        addDisposable(observable.subscribeWith(observer));
    }

    public void dispose() {
        if (!disposables.isDisposed()) {
            disposables.dispose();
        }
    }

    private void addDisposable(Disposable disposable) {
        Preconditions.checkNotNull(disposable);
        Preconditions.checkNotNull(disposables);
        disposables.add(disposable);
    }

I call useCase.execute() and later call useCase.dispose().But I call useCase.execute() again and not thing happened .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JerzyPuchalski picture JerzyPuchalski  Â·  3Comments

colintheshots picture colintheshots  Â·  3Comments

attaullahpro picture attaullahpro  Â·  3Comments

MetaiR picture MetaiR  Â·  3Comments

ramonmoraes8080 picture ramonmoraes8080  Â·  3Comments