I am struggling with promises. I see how the chain of events is happening through .then().then().then().then().then().then().then().then().then().then().then().then()
but I can not figure out how to make it end. I was hoping I could just make a simple :
.then(callback(mydata))
However, I can't get that to work. I am trying to accomplish this.
function doSomethingCallback(theArrayComesBackHere) {
theArrayComesBackHere.forEach(/*do stuff*/);
}
button.onclick = () => {
myobj.getlocalforagedata(doSomethingCallback);
}
myobj = {
getlocalforagedata: (callback) => {
var arr = [];
localForage.keys().then((keys) => {
keys.forEach((key) => {
localForage.getItem(key).then(function (results) {
arr.push(results);
});
});
callback && callback(arr);
});
}
}
Please help me break out of this madness.