export function enumerate < T > ( arr ) { return arr . map ( ( v , i ) => [ i , v ] ) ; } export async function sleep ( ms ) { await new Promise ( ( r ) => setTimeout ( r , ms ) ) ; } export function divide ( from , split ) { const arr = from . split ( split ) ; return [ arr [ 0 ] , arr . slice ( 1 ) . join ( split ) ] ; } export class PromiseQueue { queue : { promise : ( ) => Promise < any > ; call : ( ) => void ; } [ ] = [ ] ; running = false ; push = ( promise ) => new Promise < void > ( ( r ) => { this . queue . push ( { promise , call : r } ) ; if ( ! this . running ) this . run ( ) ; } ) ; async run ( ) { const task = this . queue . shift ( ) ; if ( task ) { this . running = true ; await task . promise ( ) ; task . call ( ) ; this . run ( ) ; } else { this . running = false ; } } }