type QueueItem = ( cb : ( ) => void ) => unknown ; class Queue { private _running = false ; private _queue : Array < QueueItem > = [ ] ; param { Function } f returns memberOf public push ( f ) { this . _queue . push ( f ) ; if ( ! this . _running ) { this . _next ( ) ; } return this ; } private _next ( ) { this . _running = false ; const action = this . _queue . shift ( ) ; if ( action ) { this . _running = true ; try { action ( this . _next . bind ( this ) ) ; } catch ( error ) { this . _next . call ( this ) ; } } } } export default Queue ;