/**
 * The AsyncQueue class used to sequentialize burst requests
 */ export class AsyncQueue { /**
     * The remaining amount of queued promises
     */ public get remaining ( ) : number { return this . promises . length ; } /**
     * The promises array
     */ private promises : InternalAsyncQueueDeferredPromise [ ] = [ ] ; example public wait ( ) { const next = this . promises . length ? this . promises [ this . promises . length - 1 ] . promise : Promise . resolve ( ) ; let resolve ; const promise = new Promise < void > ( ( res ) => { resolve = res ; } ) ; this . promises . push ( { resolve : resolve ! , promise } ) ; return next ; } /**
     * Frees the queue's lock for the next item to process
     */ public shift ( ) { const deferred = this . promises . shift ( ) ; if ( typeof deferred !== 'undefined' ) deferred . resolve ( ) ; } } internal interface InternalAsyncQueueDeferredPromise { resolve ( ) : void ; promise : Promise < void > ; }