export default class VarLock { public lock : Promise < void > ; private promiseRes : Function ; private rejectRes : Function ; /**
     * Creating an instance of this automatically locks it
     */ constructor ( ) { this . lockvar ( ) ; } /**
     * First waits for existing lock to release before locking right away again
     */ async lockvar ( ) { if ( this . lock ) { await this . lock ; } this . lock = new Promise ( ( resolve , reject ) => { this . promiseRes = resolve ; this . rejectRes = reject ; } ) ; } unlock ( data ? ) { this . promiseRes ( data ) ; } unlockWithError ( err ) { this . rejectRes ( err ) ; } }