Node: "for await" loop throws ​​SyntaxError: Unexpected reserved word

Created on 7 Dec 2017  ·  2Comments  ·  Source: nodejs/node

  • Version: v9.2.0
  • Platform: Darwin Osamas-MacBook-Pro.local 17.2.0 Darwin Kernel Version 17.2.0: Fri Sep 29 18:27:05 PDT 2017; root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

This code does not recognize "await" with Async iterator and throws:

SyntaxError: Unexpected reserved word

async function foo (){
    const promises = [
        fetch(`${API_URL}/api/users/1`),
        fetch(`${API_URL}/api/users/2`),
        fetch(`${API_URL}/api/users/3`),
    ]

    for await (let item of promises){
        console.log(item)
    }
}

While it's working normally with chrome V8 engine

image

Any ideas why it is not yet supported?

V8 Engine question

Most helpful comment

Async iterators are shipped in V8 6.3
To use them you need the last Node.js nightly (has V8 6.3 as of 2017.12.06).
Or you can add --harmony_async_iteration flag with the Node.js 9 (still has V8 6.2 for now).

All 2 comments

Async iterators are shipped in V8 6.3
To use them you need the last Node.js nightly (has V8 6.3 as of 2017.12.06).
Or you can add --harmony_async_iteration flag with the Node.js 9 (still has V8 6.2 for now).

Closing as @vsemozhetbyt has answered the question. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danielstaleiny picture danielstaleiny  ·  3Comments

loretoparisi picture loretoparisi  ·  3Comments

dfahlander picture dfahlander  ·  3Comments

fanjunzhi picture fanjunzhi  ·  3Comments

danialkhansari picture danialkhansari  ·  3Comments