mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-03 20:24:24 -04:00
cancel pending price request on select new provider
This commit is contained in:
parent
75e85179b4
commit
7beae49dd2
3 changed files with 29 additions and 7 deletions
|
@ -143,7 +143,7 @@ public class PriceFeedService {
|
|||
public void awaitExternalPrices() {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ChangeListener<? super Number> listener = (observable, oldValue, newValue) -> {
|
||||
if (hasExternalPrices()) latch.countDown();
|
||||
if (hasExternalPrices() && latch.getCount() != 0) latch.countDown();
|
||||
};
|
||||
updateCounter.addListener(listener);
|
||||
if (hasExternalPrices()) {
|
||||
|
@ -277,12 +277,14 @@ public class PriceFeedService {
|
|||
|
||||
// returns true if provider selection loops back to beginning
|
||||
private boolean setNewPriceProvider() {
|
||||
httpClient.cancelPendingRequest();
|
||||
boolean looped = providersRepository.selectNextProviderBaseUrl();
|
||||
if (!providersRepository.getBaseUrl().isEmpty())
|
||||
if (!providersRepository.getBaseUrl().isEmpty()) {
|
||||
priceProvider = new PriceProvider(httpClient, providersRepository.getBaseUrl());
|
||||
else
|
||||
} else {
|
||||
log.warn("We cannot create a new priceProvider because new base url is empty.");
|
||||
return looped;
|
||||
}
|
||||
return looped;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -293,7 +295,7 @@ public class PriceFeedService {
|
|||
}
|
||||
|
||||
private void setHavenoMarketPrice(String currencyCode, Price price) {
|
||||
UserThread.await(() -> {
|
||||
UserThread.execute(() -> {
|
||||
synchronized (cache) {
|
||||
if (!cache.containsKey(currencyCode) || !cache.get(currencyCode).isExternallyProvidedPrice()) {
|
||||
cache.put(currencyCode, new MarketPrice(currencyCode,
|
||||
|
@ -374,7 +376,7 @@ public class PriceFeedService {
|
|||
*/
|
||||
public synchronized Map<String, MarketPrice> requestAllPrices() throws ExecutionException, InterruptedException, TimeoutException, CancellationException {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ChangeListener<? super Number> listener = (observable, oldValue, newValue) -> { latch.countDown(); };
|
||||
ChangeListener<? super Number> listener = (observable, oldValue, newValue) -> { if (latch.getCount() != 0) latch.countDown(); };
|
||||
updateCounter.addListener(listener);
|
||||
requestAllPricesError = null;
|
||||
requestPrices();
|
||||
|
@ -442,7 +444,7 @@ public class PriceFeedService {
|
|||
faultHandler.handleFault(errorMessage, new PriceRequestException(errorMessage));
|
||||
}
|
||||
|
||||
UserThread.await(() -> updateCounter.set(updateCounter.get() + 1));
|
||||
UserThread.execute(() -> updateCounter.set(updateCounter.get() + 1));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue