import * as cp from 'child_process' ; export function exec ( cmd , args ) { return new Promise ( ( resolve , reject ) => { cp . execFile ( cmd , args , ( err , stdout , stderr ) => { if ( err ) { return reject ( err ) ; } return resolve ( { stdout , stderr } ) ; } ) ; } ) ; } export async function sleep ( ms ) { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; } export class SingleInstanceTimeout { private timerLock = false ; private timerId : NodeJS . Timeout | null = null ; public timeout ( fn , delay , ... args ) { if ( ! this . timerLock ) { this . timerLock = true ; this . timerId = setTimeout < any [ ] > ( ( ) => { this . timerLock = false ; fn ( ) ; } , delay , args ) ; } } public clear ( ) { if ( this . timerId ) { clearTimeout ( this . timerId ) ; } this . timerLock = false ; } }