How do I create a promise in Ember.js for an Ember-data model

ember.js, promise

Solution

Basically you can create a promise like this:

var promise = new Ember.RSVP.Promise(function(resolve, reject){
  // succeed
  resolve(value);
  // or reject
  reject(error);
});

and then you can use the `then` property to chain it further:

promise.then(function(value) {
  // success
}, function(value) {
  // failure
});

You can aslo have a look at this jsbin which shows how they could be implemented. And this is also very helpful.

Hope it helps.

Problem

I have an Ember-Data model. I would like to do some processing in the .then promise once it has loaded and then return the same model as a promise. This is what I have right now. How do I wrap up the return object as a promise so that other promises can be chained? ``` App.Member.find(1).then(function(member){ //do some processing here return member; // Does this need to be wrapped as a promise? } ```

Original source