hidden export class AsyncQueue < Specifier > { constructor ( public chain = Promise . resolve ( null ) ) { } add ( task ) ; add ( task ) ; add ( task ) { let result ; if ( task . then && task . catch ) { result = this . chain . then ( ( ) => task ) ; } else { result = this . chain . then ( task ) ; } this . chain = result . catch ( ( err ) => { console . error ( `[AsyncQueue] Callback chain error: ${ err . message }` , err . stack ) ; } ) ; return result ; } }