У меня есть служебная функция, которая проверяет элементы в indexeddb и делает их недействительными
invalidateCache() {
let now = Date.now()
return keys(cacheStore).then((keys) => { // 1st
keys.map((key) => {
return this.getCachedResponse(key).then((item) => { // 2nd
if (item.expire < now) {
this.deleteCache(key)
}
})
})
}).catch((err) => {
console.error(err)
})
}
Теперь мне нужно убедиться, что второе обещание разрешено, прежде чем я перейду в другую функцию, например
this.invalidateCache().then(() => { // 2nd promise has finished its work
// check the db
this.getCachedResponse()
.then((res) => {
if (res) {} // item is not expired
else {} // make http request
но, к сожалению, this.invalidateCache().then(()
решает 1-е обещание, а не вложенное.
так, как я могу продолжить цепочку после вложенного 2nd
обещания?