import { Disposable } from "vscode" ; export class Queue < T > { private _store : T [ ] = [ ] ; public push ( val ) { this . _store . push ( val ) ; } public pop ( ) { return this . _store . shift ( ) ; } public empty ( ) { if ( this . _store . length === 0 ) { return true ; } return false ; } } class TaskExecutor implements Disposable { private _tasks : Queue < any > = new Queue ( ) ; private _isExecuting : boolean = false ; public execute ( task ) { this . _tasks . push ( task ) ; this . _pickAndRun ( ) . catch ( console . error ) ; } public dispose ( ) { } private async _pickAndRun ( ) { if ( this . _isExecuting ) { return ; } this . _isExecuting = true ; const currentTask = this . _tasks . pop ( ) ; if ( ! currentTask ) { this . _isExecuting = false ; return ; } try { await currentTask ( ) ; } catch ( error ) { } this . _isExecuting = false ; this . _pickAndRun ( ) . catch ( console . error ) ; } } export const taskExecutor = new TaskExecutor ( ) ;