WalletAppKit: simplify blocking startup

* Use `startAsync()` for the blocking case, too. Since we were already
  waiting on `downloadListner.await()`
* Make sure `installShutdownHook()` is called in both cases (bug fix)
* Add more comments
This commit is contained in:
Sean Gilligan 2022-07-27 13:51:36 -07:00 committed by Andreas Schildbach
parent ff674ea605
commit bee8427761

View file

@ -378,16 +378,11 @@ public class WalletAppKit extends AbstractIdleService {
}
vChain.addWallet(vWallet);
vPeerGroup.addWallet(vWallet);
// vChain, vWallet, and vPeerGroup all initialized; allow subclass (if any) a chance to adjust configuration
onSetupCompleted();
if (blockingStartup) {
vPeerGroup.start();
// Make sure we shut down cleanly.
installShutdownHook();
vPeerGroup.startBlockChainDownload(downloadListener);
downloadListener.await();
} else {
// Start the PeerGroup (asynchronously) and start downloading the blockchain (asynchronously)
vPeerGroup.startAsync().whenComplete((result, t) -> {
if (t == null) {
vPeerGroup.startBlockChainDownload(downloadListener);
@ -395,6 +390,12 @@ public class WalletAppKit extends AbstractIdleService {
throw new RuntimeException(t);
}
});
// Make sure we shut down cleanly.
installShutdownHook();
if (blockingStartup) {
downloadListener.await(); // Wait for the blockchain to download
}
}