import { logger } from './logger' ; export class AnimationQueue { private queue : any [ ] = [ ] ; private running : boolean = false ; constructor ( ) { this . animate = this . animate . bind ( this ) ; } param object public push ( object ) { if ( this . running ) { this . queue . push ( object ) ; return ; } this . running = true ; setTimeout ( ( ) => this . animate ( object ) , 0 ) ; } param object public async animate ( object ) { try { await object . func . apply ( null , object . args ) ; } catch ( err ) { logger . error ( `animation-queue: encountered an error: ${ err } with stack trace: ${ err . stack }` ) ; } finally { if ( this . queue . length > 0 ) { this . animate . call ( this , this . queue . shift ( ) ) ; } else { this . running = false ; } } } /**
     * Clears the queue
     */ public clear ( ) { this . queue = [ ] ; } }