Resolving promises multiple times (or rather not)

Hello!

I am currently implementing an IndexedDB based local cache for my data to speed up the overall performance.

In an ideal world, the data would first be shown from the local cache (for near instantaneous rendering) and then checked for freshness from the server, if necessary updating the model and other properties.

For my current setup, I am using plain old Ember RSVP promises. So my initial idea was to

  1. resolve the promise first with the local data
  2. resolve the promise with updated server data for a second time if necessary

Yet, I’ve read that promises are brought into a final state after resolving them once, so maybe using promises are the wrong way to go?

As we have an existing code base with promises, I am thinking about either:

  1. Resetting the promise by deleting the isFulfilled and fulfillmentValue properties and resolving it again

  2. Implementing a third callback which would allow a syntax like:

     var promise = new RSVP.Promise(function(resolve, reject, update){ /* invoke either of them */ });
    
     promise.then(function(data) {
        // resolve was invoked
     }, function(data) {
        // reject was invoked
     }, function(data) {
        // update was invoked
     });
    

Both feel ‘a little’ hacky to me. What do you think? How would you approach this?

This seems to be a special case as I’ve found no similiar requests… Have I overlooked something obvious? :grin: