From ca746de8c3f75b5283bf7735211e40b000110728 Mon Sep 17 00:00:00 2001 From: Jan Kuri Date: Sun, 6 Aug 2017 19:26:21 +0200 Subject: [PATCH] feat(concurrency): fix concurrency --- src/components/app-home/app-home.component.ts | 2 +- src/ngx-uploader/classes/ngx-uploader.class.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/app-home/app-home.component.ts b/src/components/app-home/app-home.component.ts index 52004aa7..46f67d03 100644 --- a/src/components/app-home/app-home.component.ts +++ b/src/components/app-home/app-home.component.ts @@ -20,7 +20,7 @@ export class AppHomeComponent { constructor() { this.formData = { - concurrency: 0, + concurrency: 1, autoUpload: false, verbose: true }; diff --git a/src/ngx-uploader/classes/ngx-uploader.class.ts b/src/ngx-uploader/classes/ngx-uploader.class.ts index c77c4af0..5ae49879 100644 --- a/src/ngx-uploader/classes/ngx-uploader.class.ts +++ b/src/ngx-uploader/classes/ngx-uploader.class.ts @@ -2,8 +2,10 @@ import { EventEmitter } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import { Subscription } from 'rxjs/Subscription'; import { Subscriber } from 'rxjs/Subscriber'; +import 'rxjs/add/observable/of'; import 'rxjs/add/observable/from'; -import 'rxjs/add/operator/mergeAll'; +import 'rxjs/add/operator/mergeMap'; +import 'rxjs/add/operator/map'; export enum UploadStatus { Queue, @@ -133,9 +135,11 @@ export class NgUploaderService { return; } - Observable.from(files.map(file => file.sub = this.uploadFile(file, event))) - .mergeAll(concurrency) - .subscribe((data: UploadOutput) => this.serviceEvents.emit(data)); + Observable.of(...files) + .mergeMap(file => { + return this.uploadFile(file, event); + }, concurrency) + .subscribe(data => this.serviceEvents.emit(data)); break; case 'cancel': const id = event.id || null;