@@ -2,7 +2,7 @@ import { Component, OnInit, OnDestroy } from '@angular/core';
22import { BackendService } from '../services/backend.service' ;
33import { KartoffelstampfTerminalOutputEntry , KartoffelstampfCompressInstruction } from '../types/kartoffelstampf-server' ;
44import { TerminalLine , CompressImageJobItem } from '../types/kartoffelstampf-client' ;
5- import { finalize , takeUntil } from 'rxjs/operators' ;
5+ import { finalize , takeUntil , takeWhile , endWith } from 'rxjs/operators' ;
66import { Subject , throwError , of , EMPTY } from 'rxjs' ;
77import { catchError } from 'rxjs/operators' ;
88import { HttpErrorResponse } from '@angular/common/http' ;
@@ -57,6 +57,8 @@ export class UploadPageComponent implements OnInit, OnDestroy {
5757 uiStateDragLeave = true ;
5858
5959 activeStep = 1 ;
60+ concurrentJobLimit = 5 ;
61+ concurrentJobCount = 0 ;
6062
6163 constructor ( private backendService : BackendService ) { }
6264
@@ -146,30 +148,35 @@ export class UploadPageComponent implements OnInit, OnDestroy {
146148
147149 runCompressCommand ( job : CompressImageJobItem ) {
148150 const self = this ;
149- self . backendService . runCompressCommand ( < KartoffelstampfCompressInstruction > {
150- compressType : KartoffelstampfCompressInstruction . COMPRESS_TYPE_LOSSLESS ,
151- temporaryFileName : job . temporaryFileName ,
152- } )
153- . pipe (
154- finalize ( ( ) => {
155- job . compressDone = true ;
156- } ) ,
157- takeUntil ( self . preDestroy )
158- )
159- . subscribe ( data => {
160- if ( data . type === 'compressResult' ) {
161- job . compressedSize = data . payload [ 'compressedSize' ] ;
162- } else {
163- const terminalLine = new TerminalLine ( data ) ;
164- const previousTerminalLine = job . terminalLines [ job . terminalLines . length - 1 ] ;
165- if ( previousTerminalLine !== undefined &&
166- previousTerminalLine . clearLine === true &&
167- terminalLine . clearLine === true ) {
168- job . terminalLines . pop ( ) ;
169- }
170- job . terminalLines . push ( terminalLine ) ;
151+ const intervallId = setInterval ( function ( ) {
152+ if ( self . concurrentJobCount < self . concurrentJobLimit ) {
153+ clearInterval ( intervallId ) ;
154+ self . concurrentJobCount = self . concurrentJobCount + 1 ;
155+ self . backendService . runCompressCommand ( < KartoffelstampfCompressInstruction > {
156+ compressType : KartoffelstampfCompressInstruction . COMPRESS_TYPE_LOSSLESS ,
157+ temporaryFileName : job . temporaryFileName ,
158+ } )
159+ . pipe (
160+ finalize ( ( ) => self . concurrentJobCount = self . concurrentJobCount - 1 ) ,
161+ takeUntil ( self . preDestroy ) ,
162+ )
163+ . subscribe ( data => {
164+ if ( data . type === 'compressResult' ) {
165+ job . compressedSize = data . payload [ 'compressedSize' ] ;
166+ job . compressDone = true ;
167+ } else {
168+ const terminalLine = new TerminalLine ( data ) ;
169+ const previousTerminalLine = job . terminalLines [ job . terminalLines . length - 1 ] ;
170+ if ( previousTerminalLine !== undefined &&
171+ previousTerminalLine . clearLine === true &&
172+ terminalLine . clearLine === true ) {
173+ job . terminalLines . pop ( ) ;
174+ }
175+ job . terminalLines . push ( terminalLine ) ;
176+ }
177+ } ) ;
171178 }
172- } ) ;
179+ } , 300 ) ;
173180 }
174181
175182}
0 commit comments