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

19 lines
408 B
CoffeeScript
Raw Normal View History

# Your browser must support async/await and speech synthesis
# to run this example.
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 14:26:34 -05:00
say = (text) ->
window.speechSynthesis.cancel()
2016-11-06 14:26:34 -05:00
window.speechSynthesis.speak new SpeechSynthesisUtterance text
2016-11-06 05:30:01 -05:00
countdown = (seconds) ->
2016-11-05 05:54:18 -04:00
for i in [seconds..1]
say i
2016-11-06 05:30:01 -05:00
await sleep 1000 # wait one second
2016-11-06 14:26:34 -05:00
say "Blastoff!"
2016-11-06 05:30:01 -05:00
countdown 3