r/coffeescript • • Jul 29 '19

Are we going to have for await in CoffeeScript?

This syntax is very useful to work with streams.

4 Upvotes

1 comment sorted by

1

u/Shanebdavis Sep 05 '19

Playing around I came up with this function to bridge the gap. It's not as nice as a built-in language solution, but it's not bad.

# defined in a lib somewhere
forAwait = (iter, f) ->
  out = []
  `for await (let v of iter) {out.push(await f(v));}`
  await out

# in use:
forAwait iter, (v) -> 
  # doSomething

I based it on the description of for-await here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of