@serhalp and I took a pass at fixing this, but it's pretty nuanced. Here's our current thinking about read_array_cache.coffee:
Currently the order is:
Flush writes
Kick off an async HTTP request and sometime later resolve the array $promise and $httpPromise
If we have local data, load it from the cache and resolve the array $promise
Because of the async nature of the HTTP request, there are a couple states where we'd need to manage promises on the individual objects in the arrays:
We have local data so the Array $promise is resolved, but we're waiting on the array $httpPromise, so we want the objects in the array to have their own $promise resolved with the cached object and an $httpPromise that is not resolved
When the HTTP data comes back from the server the Array $promise and $httpPromise are resolved, so we want the objects in the array to have $promise resolved (either it was already resolved with local data in step 3 or if there was no local data it now gets resolved with fresh data) and $httpPromise resolved with the modified data (server + local via modifyObjectInPlace)
Currently, when you read a single value from the cache,
$promise
and$httpPromise
are set on the object:However, when you read an array value from the cache, it's more complicated, and currently
$promise
and$httpPromise
are only set on the Array and not the objects in the array.@serhalp and I took a pass at fixing this, but it's pretty nuanced. Here's our current thinking about
read_array_cache.coffee
:Currently the order is:
Because of the async nature of the HTTP request, there are a couple states where we'd need to manage promises on the individual objects in the arrays: