Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug caused by incorrect usage of Promise #3385

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,23 @@ public void initialize(Promise<Void> initializePromise) {
currencyServerUrl,
defaultTimeout,
httpClient));
populatesLatestCurrencyRates(currencyServerUrl, defaultTimeout, httpClient);
populatesLatestCurrencyRates(currencyServerUrl, defaultTimeout, httpClient)
.onComplete(initializePromise);

externalConversionProperties.getMetrics().createCurrencyRatesGauge(this::isRatesStale);
} else {
initializePromise.tryComplete();
}

initializePromise.tryComplete();
}

/**
* Updates latest currency rates by making a call to currency server.
*/
private void populatesLatestCurrencyRates(String currencyServerUrl, Long defaultTimeout, HttpClient httpClient) {
httpClient.get(currencyServerUrl, defaultTimeout)
private Future<Void> populatesLatestCurrencyRates(String currencyServerUrl,
Long defaultTimeout,
HttpClient httpClient) {

return httpClient.get(currencyServerUrl, defaultTimeout)
.map(this::processResponse)
.map(this::updateCurrencyRates)
.otherwise(this::handleErrorResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public DaemonVerticle(List<Initializable> initializables, List<ScheduledReporter

@Override
public void start(Promise<Void> startPromise) {
startPromise.handle(all(initializables, initializable -> initializable::initialize));
all(initializables, initializable -> initializable::initialize).onComplete(startPromise);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the bug fix for #2733 (comment) ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the primary goal of this PR is to address that comment.
However, we need confirmation from @And1sS, as it was his idea to implement it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the startup issue

}

@Override
public void stop(Promise<Void> stopPromise) {
stopPromise.handle(all(closeables, closeable -> closeable::close));
all(closeables, closeable -> closeable::close).onComplete(stopPromise);
}

private static <E> Future<Void> all(Collection<E> entries,
Expand Down
Loading