import Bottleneck from 'bottleneck' ; import { state } from '@lib/state' ; export interface IQueue { add ( job ) : void ; stop ( ) : void ; } class Queue implements IQueue { protected limiter : Bottleneck ; constructor ( ) { this . limiter = new Bottleneck ( { maxConcurrent : state . get ( 'concurrency' ) } ) ; state . on ( 'set:concurrency' , ( value ) => { this . limiter . updateSettings ( { maxConcurrent : value } ) ; } ) ; } public add ( job ) { const wrapped = this . limiter . wrap ( job ) ; wrapped ( ) ; } public stop ( ) { this . limiter . stop ( ) ; } } export const queue = new Queue ( ) ;