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

ES7 await #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

ES7 await #19

wants to merge 5 commits into from

Conversation

therealmarv
Copy link

I'm no ES7 expert. Somebody with more knowledge may review it.

It looks much nicer for me.

Credits go to @lukehoban

@mathbruyen
Copy link

Minor point but you may use await* instead of await Promise.all(...). The spec proposal feels a bit unsure about it so it may change, but it works with babel.

@carlosvillu
Copy link

@mathbruyen is right. With await* you follow the spec and is easier to read.

@lukehoban
Copy link

My understanding is that await* is not part of the ES7 timeframe async/await proposal. At least it doesn't appear to be in the spec draft that @bterlson is writing.

@carlosvillu
Copy link

I am working in something that is using that.

https://github.com/carlosvillu-com/graphql-basic/blob/master/pokemon-client.js#L11

What do you think ?!

2015-07-10 23:47 GMT+02:00 Luke Hoban [email protected]:

My understanding is that await* is not part of the ES7 timeframe
async/await proposal. At least it doesn't appear to be in the spec draft
https://tc39.github.io/ecmascript-asyncawait/ that @bterlson
https://github.com/bterlson is writing.


Reply to this email directly or view it on GitHub
#19 (comment)
.

@mathbruyen
Copy link

In your case the descriptions method actually synchronously returns an array of promises, while await* will make it return a single promise once all in the array are fulfilled (or any is rejected). If you want to see the difference in action, run the following (tried with babel 5.1.10) with babel-node --stage 1 test.js, then remove the * in ``foo` and re-run it.

function wait(i) {
  return new Promise(resolve => {
    setTimeout(() => {
      console.log('Resolve', i);
      resolve(i * 2);
    }, i * 1000);
  });
}
async function foo() {
  return await* [1, 2, 3, 4].map(wait);
}
foo().then(arr => console.log(arr));

With the * it displays fist Resolve X each second and then the doubled array. Without it, an array of promises is displayed and later Resolve X appear.

@carlosvillu
Copy link

You are right! ... Thank for the info. But I think that in my particular
case, is better use it without "*".
I have to fine tune my es6 knowledge.

2015-07-13 11:51 GMT+02:00 Mathieu Bruyen [email protected]:

In your case the descriptions method actually synchronously returns an
array of promises, while await* will make it return a single promise once
all in the array are fulfilled (or any is rejected). If you want to see the
difference in action, run the following (tried with babel 5.1.10) with babel-node
--stage 1 test.js, then remove the * in `foo and re-run it.

function wait(i) {
return new Promise(resolve => {
setTimeout(() => {
console.log('Resolve', i);
resolve(i * 2);
}, i * 1000);
});
}
async function foo() {
return await* [1, 2, 3, 4].map(wait);
}
foo().then(arr => console.log(arr));

With the * it displays fist Resolve X each second and then the doubled
array. Without it, an array of promises is displayed and later Resolve X
appear.


Reply to this email directly or view it on GitHub
#19 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants