Last active
December 4, 2015 16:07
-
-
Save stvnjacobs/84e2ea3c1bdab3464102 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = Promise.resolve(queryRange(start, end)); | |
data.then(function(values) { | |
console.log(values); | |
}); | |
function queryRange(start, end) { | |
var data = []; | |
var start = parseInt(start, 10); | |
var end = parseInt(end, 10); | |
var length = (end - start) + 1; | |
var localforagePromises = []; | |
for (i = 0; i != length; i++) { | |
var key = (start + i).toString(); // keys are '47513199', '47513200', '47513201', etc. | |
var localforagePromise = localforage.getItem(key).then(function(value) { return value }); | |
var localforageResolve = Promise.resolve(localforagePromise); | |
localforagePromises.push(localforageResolve); | |
} | |
var dataPromise = Promise.all(localforagePromises).then(function(values) { return values }); | |
return dataPromise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment