I have an Android project that is using the FileStack dependency that is relying on RX Java 2. Specifically, io.reactivex.rxjava2:rxjava:2.1.2
. This has not really been a problem up until now as I have been unable to figure out how to specifically cancel a Flowable.
I have implemented the
Here is my code below:
private Flowable<Progress<FileLink>> upload;
private void myMethod(){
upload = new Client(myConfigOptionsHere)
.uploadAsync(filePath, false, storageOptions);
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(){
//What do I do here to manually stop the upload Flowable?
//IE upload.cancel();
}
What do I need to do / call against the upload
Flowable so that I can manually trigger a cancel when the user cancels the upload via a button click? I see people recommending calling dispose
, but I don't see that option when checking the available methods to use against the Flowable.