mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-03-22 23:28:48 +00:00
avoid race condition
This commit is contained in:
parent
98c095b568
commit
e979a352fb
1 changed files with 60 additions and 57 deletions
|
@ -848,6 +848,9 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] =
|
||||
subscriptionCreationTime;
|
||||
|
||||
// Doublecheck to avoid race condition.
|
||||
if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] ==
|
||||
null) {
|
||||
// Set stream subscription.
|
||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
|
||||
subscription.responseStream.asBroadcastStream().listen((event) {
|
||||
|
@ -876,15 +879,16 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
level: LogLevel.Error);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
// A subscription already exists.
|
||||
//
|
||||
// Resume the stream subscription if it's paused.
|
||||
if (ElectrumxChainHeightService
|
||||
.subscriptions[cryptoCurrency.coin]!.isPaused) {
|
||||
// If it's paused, resume it.
|
||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!
|
||||
.resume();
|
||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!.resume();
|
||||
}
|
||||
|
||||
// Causes synchronization to stall.
|
||||
|
@ -913,7 +917,6 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
|||
// Retry/recurse.
|
||||
return await _manageChainHeightSubscription();
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the subscription has been running for too long.
|
||||
if (ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] != null) {
|
||||
|
|
Loading…
Reference in a new issue