How to wait for a promise to be fulfilled before continuing

ember.js

Solution

With ES6, you can now use the `async/await` syntax. It makes the code much more readable:

async getSomeOption() {
  var option = null;
  if (mustHaveOption) {
    option = await store.find("option", 1)
  }
}
return option;

PS: this code could be simplified, but I'd rather keep it close from the example given above.

Problem

How can I wait until a Promise is resolved before executing the next line of code? e.g. ``` var option = null; if(mustHaveOption){ option = store.find("option", 1).then(function(option){ return option }) } //wait until promise is resolved before returning this value return option; ```

Original source

Related problems