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

Promise.then doesn't wait #293

Open
OliverJAsh opened this issue Dec 8, 2015 · 5 comments
Open

Promise.then doesn't wait #293

OliverJAsh opened this issue Dec 8, 2015 · 5 comments

Comments

@OliverJAsh
Copy link

i.e.:

require(['bootstraps/standard'])
    .then(() => (
        new Promise(resolve => setTimeout(() => resolve(), 500))
            .then(() => console.log('foo')))
    )
    .then(() => console.log('bar'))

bar will fire before foo.

I'm happy to cast the promise using Promise.resolve, but can this be documented?

@unscriptable
Copy link
Member

How's this, @OliverJAsh?

@Earl-Brown
Copy link

Could it be that you're not returning the promise?

Try this:

require(['bootstraps/standard'])
    .then(() => (
        return new Promise(resolve => setTimeout(() => resolve(), 500))
            .then(() => console.log('foo')))
    )
    .then(() => console.log('bar'))

In the original version, nothing is returned, so that nothing gets passed immediately into the second "then". But if you return a promise from a "then", it kind of replaces all of the following "then".

I think that's the way the spec says it should wrok.

@OliverJAsh
Copy link
Author

@Earl-Brown I am using an arrow function which has an implicit return.

@Earl-Brown
Copy link

Ah ... that makes sense, then.

@haouarihk
Copy link

when you use arrow function like this (e)=>{//code here}
it doesn't return the data inside by default only when you use
(e)=>//code here
its the same as
(e)=>{return //code here}

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

No branches or pull requests

4 participants