diff --git a/documentation/coffee/async.coffee b/documentation/examples/async.coffee similarity index 65% rename from documentation/coffee/async.coffee rename to documentation/examples/async.coffee index 23dd85f0..1b95b6ee 100644 --- a/documentation/coffee/async.coffee +++ b/documentation/examples/async.coffee @@ -1,15 +1,18 @@ +# Your browser must support async/await and speech synthesis +# to run this example. + sleep = (ms) -> new Promise (resolve) -> window.setTimeout resolve, ms say = (text) -> - window.speechSynthesis.cancel() # cancel any prior utterances + window.speechSynthesis.cancel() window.speechSynthesis.speak new SpeechSynthesisUtterance text countdown = (seconds) -> for i in [seconds..1] - say "#{i}" + say i await sleep 1000 # wait one second say "Blastoff!" -countdown(3) +countdown 3 diff --git a/documentation/js/async.js b/documentation/js/async.js deleted file mode 100644 index 5c13b246..00000000 --- a/documentation/js/async.js +++ /dev/null @@ -1,23 +0,0 @@ -// Generated by CoffeeScript 2.0.0-alpha -var countdown, sleep; - -sleep = function(ms) { - return new Promise(function(resolve) { - return window.setTimeout(resolve, ms); - }); -}; - -countdown = async function(seconds) { - var i, j, ref, utterance; - for (i = j = ref = seconds; ref <= 1 ? j <= 1 : j >= 1; i = ref <= 1 ? ++j : --j) { - if (window.speechSynthesis != null) { - utterance = new SpeechSynthesisUtterance("" + i); - window.speechSynthesis.speak(utterance); - } - console.log(i); - await sleep(1000); - } - return alert("Done! (Check the console!)"); -}; - -countdown(3);