I'm wondering why $.when is resolving too early? I need it to resolve only when all the others promises have resolved. Am I missing something?
Update: http://jsfiddle.net/7hdx5j6z/6/
var promises = []
localforage.iterate(function(value, key) {
if ( key.indexOf('params_') === -1 ) {
promises.push(localforage.removeItem(key))
console.log(promises)
}
})
$.when.apply($, promises).then(function() {
console.log('all done!')
})
iterate
itself returns a promise. You need to wait on that before the promises
array is populated.
var promises = []
var x = localforage.iterate(function (value, key) {
if (key.indexOf('params_') === -1) {
var promise = localforage.removeItem(key)
promises.push(promise)
console.log(promise)
}
})
console.log("x", x);
x.then(function () {
$.when.apply($, promises).then(function () {
console.log('all done!')
})
});