export class Lock { latch : Promise < any > ; count : number ; unlock ! : Function ; constructor ( count = 1 ) { this . count = count ; let lock = this ; this . latch = new Promise ( ( resolve ) => { this . unlock = function ( ) { lock . count -= 1 ; if ( lock . count === 0 ) { resolve ( ) ; } } ; } ) ; } } export function wait ( millis = 100 ) { return new Promise ( ( resolve ) => { setTimeout ( ( ) => { resolve ( ) ; } , millis ) ; } ) ; } export function sleep ( ms ) { let start = new Date ( ) . getTime ( ) , expire = start + ms ; while ( new Date ( ) . getTime ( ) < expire ) { } }