Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silent break on iterations including async when storing args to variable #2180

Closed
Radivarig opened this issue Aug 8, 2015 · 1 comment
Closed
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@Radivarig
Copy link

In async functions where I use map or store args to variable, babel breaks.

Using map:

var someArray = ['foo', 'bar', 'fuzz']
someArray.map(function(x){
  var someAsyncVar = await doSomeAsyncStuff(x)
  console.log('someAsyncVar', someAsyncVar) //not executed
})

Storing string:

for (var i = 0; i < someArray.length; ++i) {
  var x = someArray[i] //this breaks it
  var someAsyncVar = await doSomeAsyncStuff(x)

But this works:

for (var i = 0; i < someArray.length; ++i) {
  var someAsyncVar = await doSomeAsyncStuff(someArray[i]) //works when passed by index
  console.log('someAsyncVar', someAsyncVar) //does execute
}

Using "babel": "^5.6.14" and to compile runtimeGenerator from async/await:

babel ./synthax_code.js --out-file ./synthax_code-compiled.js --stage 1
@zloirock
Copy link
Member

zloirock commented Aug 8, 2015

Expected behavior. You can use await only in async functions, but in first example you are using it in sync .map callback. Second example works correct in async function.

@zloirock zloirock closed this as completed Aug 8, 2015
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 13, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants