1

I've got this very basic async await which I believe is not running correctly:

  const ex = {
    people: () => {console.log('people')},
    places: () => {console.log('places')}
  }


  async function example() {
    try {
      const people = await ex.people()
      const places = await ex.places()
    } catch(err) {
      console.log(err)
    }
  }
  example().then(console.log('last'))

output:

people
last
places

Shouldn't this be outputting 'people, places, last'?

2
  • 1
    Your people and places functions do not return Promises. Is that intentional? Commented Mar 2, 2017 at 18:10
  • Thanks for the response, I had tried this but still didn't seem to solve the problem Commented Mar 2, 2017 at 18:37

1 Answer 1

2

Yes, this code snippet is pretty much ok! The only thing missing here it's that promises returns functions.

So .then should be like this:

example().then(() => console.log('last'))

Hope it works for you!

Edit:

As @gyre said, ex.people and ex.places should return promises in order to work correctly

Here's an example

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.