0

Is it possible to convert the following code to CoffeeScript?

async function print(readable) {
  readable.setEncoding('utf8');
  let data = '';
  for await (const chunk of readable) {
    data += chunk;
  }
  console.log(data);
}

I managed to get something working, but I needed to escape into JavaScript:

print = (readable) ->
  await readable  # Force this function to be async with `await`.
  readable.setEncoding 'utf8'
  data = ''

  ```
  // Is it possible to convert this part to CoffeeScript, too?
  for await (const chunk of readable) {
    data += chunk;
  }
  ```

  console.log data

So is there a pure CoffeeScript solution?

Leftium
  • 14,018
  • 6
  • 55
  • 86

0 Answers0