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

16 lines
433 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}"
2016-11-06 05:40:24 -05:00
window.speechSynthesis.cancel() # cancel any prior utterances
2016-11-06 05:30:01 -05:00
window.speechSynthesis.speak utterance
console.log i
await sleep 1000 # wait one second
alert "Done! (Check the console!)"
countdown(3)