1 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
原來問題是我試圖處理/取消錯(cuò)誤的對象。我將代碼調(diào)整為以下內(nèi)容:
private Disposable disposable;
private void myMethod(){
Flowable<Progress<FileLink>> upload = new Client(myConfigOptionsHere)
.uploadAsync(filePath, false, storageOptions);
this.disposable = upload.doOnNext(progress -> {
double progressPercent = progress.getPercent();
if(progressPercent > 0){
//Updating progress here
}
if (progress.getData() != null) {
//Sending successful upload callback here
}
})
.doOnComplete(new Action() {
@Override
public void run() throws Exception {
//Logging he complete action here
}
})
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
//Logging the cancel here
}
})
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable t) throws Exception {
//Logging the error here
}
})
.subscribe();
}
public void cancelUpload(){
if(this.disposable != null){
this.disposable.dispose();
this.disposable = null;
}
}
并且能夠讓它正常工作。本質(zhì)上,您需要dispose()針對對象調(diào)用方法dispose,而不是Flowable.
添加回答
舉報(bào)