0

I have a asynchronous loop for getting payload:

let payload = "";
for await (const chunk of body) {
  payload += chunk;
}

But this code is no supported by ESLint:

error iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations no-restricted-syntax

How to implement for-await-of to supported loop format by ESLint, eg. forEach(), map(), reduce()? As asynchronous function?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
deSoul
  • 95
  • 8
  • Is `body` an array? – VLAZ Mar 22 '21 at 12:21
  • Is `body` an array of promises? – evolutionxbox Mar 22 '21 at 12:24
  • Yes, this example code was taken from the official documentation for elasticsearch client: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/as_stream_examples.html – deSoul Mar 22 '21 at 12:25
  • Just move the `await` keyword between `+=` and `chunk`. You can use any of the alternatives posted [here](https://stackoverflow.com/a/40329190/5459839). – trincot Mar 22 '21 at 12:26

0 Answers0