1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00
jashkenas--coffeescript/documentation/coffee/async.coffee

15 lines
365 B
CoffeeScript
Raw Normal View History

2016-11-05 05:54:18 -04:00
sleep = (ms) ->
new Promise (resolve) ->
window.setTimeout resolve, ms
2016-11-04 17:20:27 -04:00
2016-11-06 05:30:01 -05:00
countdown = (seconds) ->
2016-11-05 05:54:18 -04:00
for i in [seconds..1]
2016-11-06 05:30:01 -05:00
if window.speechSynthesis?
utterance = new SpeechSynthesisUtterance "#{i}"
window.speechSynthesis.speak utterance
console.log i
await sleep 1000 # wait one second
alert "Done! (Check the console!)"
countdown(3)