mirror of
https://github.com/bitcoinj/bitcoinj.git
synced 2025-02-24 14:50:57 +01:00
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:
parent
ff674ea605
commit
bee8427761
1 changed files with 15 additions and 14 deletions
|
@ -378,23 +378,24 @@ 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();
|
||||
// Start the PeerGroup (asynchronously) and start downloading the blockchain (asynchronously)
|
||||
vPeerGroup.startAsync().whenComplete((result, t) -> {
|
||||
if (t == null) {
|
||||
vPeerGroup.startBlockChainDownload(downloadListener);
|
||||
} else {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
|
||||
vPeerGroup.startBlockChainDownload(downloadListener);
|
||||
downloadListener.await();
|
||||
} else {
|
||||
vPeerGroup.startAsync().whenComplete((result, t) -> {
|
||||
if (t == null) {
|
||||
vPeerGroup.startBlockChainDownload(downloadListener);
|
||||
} else {
|
||||
throw new RuntimeException(t);
|
||||
}
|
||||
});
|
||||
// Make sure we shut down cleanly.
|
||||
installShutdownHook();
|
||||
|
||||
if (blockingStartup) {
|
||||
downloadListener.await(); // Wait for the blockchain to download
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue