diff --git a/documentation/coffee/async.coffee b/documentation/coffee/async.coffee index fab2f569..dceee4e3 100644 --- a/documentation/coffee/async.coffee +++ b/documentation/coffee/async.coffee @@ -2,13 +2,13 @@ sleep = (ms) -> new Promise (resolve) -> window.setTimeout resolve, ms -window.countdown = (seconds) -> - if not window.speechSynthesis? - alert('speech API not supported in your browser') - return - +countdown = (seconds) -> for i in [seconds..1] - utterance = new SpeechSynthesisUtterance("#{i}") - speechSynthesis.speak(utterance) - await sleep(1000) # wait one second - alert "done!" + 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) diff --git a/documentation/index.html.js b/documentation/index.html.js index a49f75b6..11f037a3 100644 --- a/documentation/index.html.js +++ b/documentation/index.html.js @@ -868,7 +868,7 @@ Block may be used if you need to force a generator that doesn't yield.
- <%= codeFor('async', 'countdown(3)') %> + <%= codeFor('async', true) %>
Similar to how yield return forces a generator, await return
may be used to force a function to be async.
diff --git a/documentation/js/async.js b/documentation/js/async.js
new file mode 100644
index 00000000..5c13b246
--- /dev/null
+++ b/documentation/js/async.js
@@ -0,0 +1,23 @@
+// 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);