diff --git a/02-async-js/hard (promises)/2-sleep-completely.js b/02-async-js/hard (promises)/2-sleep-completely.js index 499a5647..8febbff1 100644 --- a/02-async-js/hard (promises)/2-sleep-completely.js +++ b/02-async-js/hard (promises)/2-sleep-completely.js @@ -1,8 +1,20 @@ -/* - * Write a function that halts the JS thread (make it busy wait) for a given number of milliseconds. - * During this time the thread should not be able to do anything else. - */ +function promiseBody(resolve,reject){ +var timeNow =Date.now(); +while((Date.now()-timeNow)/1000<=seconds) +{ + +} +resolve('busy wait done') +} function sleep (seconds) { + var promise = new Promise(promiseBody); + return promise; +} -} \ No newline at end of file +function printfn() { + console.log('thread was halt for'+' '+seconds+' '+'seconds' ); +} +var seconds=5; +var answer= sleep(seconds); +answer.then(printfn);