Cancel and cancelAll upload
Current behavior: (type: cancel) = On a list of files, when I cancel the current uploading file, it cancel the uploading but don't pass to the next uploading.
(type: cancelAll): It cancel all the list but when I import new files it doesn't restart the uploading.
Expected behavior: When I cancel one or more downloads, it must cancel (it is already the case) but when we import other files, it must restart the download.
Version:
- ngx-uploader: 4.2.2
- Angular: 5.2.0
Is it a issue or I miss something ?
its a known issue but cannot be solved inside the module. please check https://github.com/bleenco/ngx-uploader/issues/9 for a working sample.
I'm not sure number 9 answers mine.
I have no problem importing files into the module but it is with the cancel feature.
I do not have the knowledge level to help you with Observables but it seems to me that the flow does not go to the next. I do not know if there is a way to do that...
Maybe a solution for the cancelAll, we should reinitalize the uploaderScheduler at the end of the case 'cancelAll' with a function like:
initUploadScheduler(concurrency: number): void {
this.uploadScheduler = new Subject();
this.uploadScheduler
.mergeMap(upload => this.startUpload(upload), concurrency)
.subscribe(uploadOutput => this.serviceEvents.emit(uploadOutput));
}
What is the status here? I ran into the issue by cancelAll, but can not find the solution anywhere. Is there a workaround?
@jkuri this one is not the same as #9 because it happens when there are more cancelled (and/or running) uploads than the value of the concurrency option. Let me explain why this one happens:
- uploadScheduler is a Subject and every started upload Observable is merged by mergeMap operator but limited by concurrency option
- on completion of the Observable returned by startUpload method mergeMap cleans up normally so far so good
- on cancel the actual Subscription is subs array is unsubscribed (as it should) so when xhr is aborted and change to XMLHttpRequest.DONE state then although observer.next() and observer.complete() calls run they will not call complete because observer is already stopped
- because observer have not been completed nor errored out so the observer in startUpload have not been completed (because neither error nor complete functions have been called)
- because the observer of startUpload is the mergeMap operator (it maintains inner subscriptions) then the mergeMap operator can not clean up this Observable causing a hang up (and probably a memory leak too) when there are cancelled uploads
Subscription provides a method to add a tear down logic which is called on unsubscribe. We can use that to complete observer when unsubscribe happens. It won't complete it twice because completing it sets it to stopped and when it is stopped it won't do anything again.
I will create a PR today and post it here too. (Where can I find the CLA which I should sign?)
OK, I can not reproduce this kind of behavior with the demo app which uses Angular 7 and RxJS 6. I use Angular 5.2 too and when I upgrade ngx-uploader to 7.1.0 then if I would like to upload a new file after cancel then it won't start until the previous one completes. My fix would solve that but the upload still completes in the background then (devtools show pending request instead of cancelled). I am not aware the changes between the two versions (namely the 4.2 line and 7.1.0) but since this makes it possible to bypass concurrency limits (or maybe I am missing something) then probably upgrading to Angular 7, RxJS 6 and ngx-uploader 7.1.0 can solve this issue in my case.