maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
727 stars 58 forks source link

Nested awaits #143

Closed catvir closed 9 years ago

catvir commented 9 years ago

The await does not work with code blocks that are also using await. The following example shows the issue:

await
  console.log 1
  await setTimeout defer(), 5000
  console.log 2
  setTimeout defer(), 5000
  console.log 3
console.log 4

i'd expect it to make two pauses, one after 1, and one after 3. Only one pause happens, the one after 3, where it waits for both timers to finish and results in deadlock messages. Is this a bug or are nested awaits considered to be bad-practice?

maxtaco commented 9 years ago

This structure/syntax isn't supported, but you can achieve the same ends with function nesting.