question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Asynchronous iteration (for-await-of) and ForOfStatement deprecation

See original GitHub issue
'use strict';

(async () => {
  for await (const item of [Promise.resolve('a'), Promise.resolve('b')]) {
    console.log(item);
  }
})();
  4:3  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

Should the ForOfStatement entry in no-restricted-syntax be alleviated in such cases? Maybe it is worth to remove the second part of the message (“loops should be avoided in favor of array iterations”), since there seems to be no easy different way for array asynchronous iteration?

Is there a way for AST parser to distinguish an async ForOfStatement from a sync one?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
ljharbcommented, Mar 4, 2018

@vsemozhetbyt if you’re in a node-only environment, you can certainly override rules that are concerned with transpilation overhead.

1reaction
ljharbcommented, Mar 24, 2021

For learning how the language works, a style guide isn’t going to be super helpful. Use every part of the language to learn! A style guide helps you mitigate and avoid and minimize the bad parts, once you already know how they work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

for await...of - JavaScript - MDN Web Docs
The for await...of statement creates a loop iterating over async iterable objects as well as sync iterables. This statement can only be used ......
Read more >
Async iteration and generators - The Modern JavaScript Tutorial
Asynchronous iteration allow us to iterate over data that comes asynchronously, ... That's why async generators work with for await...of .
Read more >
Documentation - TypeScript 2.3
This kind of iterator is useful for iterating over synchronously available values, such as the elements of an Array or the keys of...
Read more >
for await...of - JavaScript - UDN Web Docs: MDN Backup
The for await...of statement creates a loop iterating over async iterable objects as well as on sync iterables, including: built-in String , Array...
Read more >
Asynchronous Iterators in JavaScript | Codementor
A for..of statement creates a loop capable of iterating over iterable objects. The statement starts by invoking the custom [Symbol.iterator]() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found