import queue from 'queue' ; import { Injectable } from '@angular/core' ; @ Injectable ( { providedIn : 'root' , } ) export class HsQueuesService { queues : { [ usecase ] : { q : any ; } ; } = { } ; ensureQueue ( useCase , customConcurrency ? ) { if ( this . queues [ useCase ] ) { return this . queues [ useCase ] . q ; } const newQueue = { q : queue ( { results : [ ] , concurrency : customConcurrency || 5 } ) , } ; this . queues [ useCase ] = newQueue ; newQueue . q . autostart = true ; newQueue . q . on ( 'end' , ( ) => { delete this . queues [ useCase ] ; } ) ; return newQueue . q ; } }