0

I have a problem. I use a AsyncStorage as a cache in my mobile app. But now I face a problem with Promises. I have a static method which looks like this:

static getDiscounts(categoryAndPage) {
    return AsyncStorage.getItem(categoryAndPage).then(discounts => {
        return discounts
    })
}

I expecting that return value should be just some json. But it returns another promise.

var cachedDiscounts = DiscountsCache.getDiscounts(discountCacheKey);
console.log(cachedDiscounts)

This above is a promise which contains my data

I dont want to call then on this.. How to fix this?

Erazihel
  • 7,295
  • 6
  • 30
  • 53
TjDillashaw
  • 787
  • 1
  • 12
  • 29
  • Your expectations are wrong. Use `then()` – charlietfl Jul 05 '17 at 21:48
  • 1
    You can't return the result of an asynchronous function: It does not exist at the time the return happens. Promises do not make asynchronous functions synchronous. – Quentin Jul 05 '17 at 21:48
  • But I want to just return this value from this function.Not promise. How to wait for promise to finish inside ```DiscountsCache``` class and then return the value? – TjDillashaw Jul 05 '17 at 21:58
  • `How to wait for promise to finish` - like this `DiscountsCache.getDiscounts(discountCacheKey).then(cachedDistcounts => console.log(cachedDiscounts))` – Jaromanda X Jul 05 '17 at 22:10

0 Answers0