mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-14 01:07:55 -05:00
change async code snippet
This commit is contained in:
@@ -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!")
|
||||
|
||||
Reference in New Issue
Block a user