From ea3f044816738121cde2fb2aceec11fbcc92b94e Mon Sep 17 00:00:00 2001
From: Gabe
Date: Sun, 6 Nov 2016 02:30:01 -0800
Subject: [PATCH] refine sound example
---
documentation/coffee/async.coffee | 18 +++++++++---------
documentation/index.html.js | 2 +-
documentation/js/async.js | 23 +++++++++++++++++++++++
3 files changed, 33 insertions(+), 10 deletions(-)
create mode 100644 documentation/js/async.js
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);