set price feed state in UserThread

This commit is contained in:
woodser 2023-12-29 05:58:43 -05:00
parent c55fb927f2
commit c6b1d03283

View File

@ -284,13 +284,15 @@ public class PriceFeedService {
} }
private void setHavenoMarketPrice(String currencyCode, Price price) { private void setHavenoMarketPrice(String currencyCode, Price price) {
if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) { UserThread.await(() -> {
cache.put(currencyCode, new MarketPrice(currencyCode, if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) {
MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT), cache.put(currencyCode, new MarketPrice(currencyCode,
0, MathUtils.scaleDownByPowerOf10(price.getValue(), CurrencyUtil.isCryptoCurrency(currencyCode) ? CryptoMoney.SMALLEST_UNIT_EXPONENT : TraditionalMoney.SMALLEST_UNIT_EXPONENT),
false)); 0,
updateCounter.set(updateCounter.get() + 1); false));
} updateCounter.set(updateCounter.get() + 1);
}
});
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@ -298,12 +300,13 @@ public class PriceFeedService {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
public void setCurrencyCode(String currencyCode) { public void setCurrencyCode(String currencyCode) {
if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) { UserThread.await(() -> {
this.currencyCode = currencyCode; if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) {
currencyCodeProperty.set(currencyCode); this.currencyCode = currencyCode;
if (priceConsumer != null) currencyCodeProperty.set(currencyCode);
applyPriceToConsumer(); if (priceConsumer != null) applyPriceToConsumer();
} }
});
} }
@ -428,7 +431,7 @@ public class PriceFeedService {
faultHandler.handleFault(errorMessage, new PriceRequestException(errorMessage)); faultHandler.handleFault(errorMessage, new PriceRequestException(errorMessage));
} }
updateCounter.set(updateCounter.get() + 1); UserThread.await(() -> updateCounter.set(updateCounter.get() + 1));
return result; return result;
} }