From 327395d793722c23abfb01f0ea00a33c85dc435c Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 5 Nov 2016 02:54:18 -0700 Subject: [PATCH] change async code snippet --- documentation/coffee/async.coffee | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/documentation/coffee/async.coffee b/documentation/coffee/async.coffee index bb1d7a42..120d81a4 100644 --- a/documentation/coffee/async.coffee +++ b/documentation/coffee/async.coffee @@ -1,10 +1,9 @@ -concatPages = (urls) -> - string = "" - for url in urls - # fetchURL returns a 'thenable' A+/Promise object - string += await fetchURL(url) - string +sleep = (ms) -> + new Promise (resolve) -> + window.setTimeout resolve, ms -concatPages([page, otherPage, yetAnother]) - .then (string) -> - console.log "Concatenation result: #{string}" +window.countdown = (seconds) -> + for i in [seconds..1] + alert("#{i} second(s) to go...") + await sleep(1000) # wait one second + alert("done!")