mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-25 19:55:52 +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] =
|
ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] =
|
||||||
subscriptionCreationTime;
|
subscriptionCreationTime;
|
||||||
|
|
||||||
|
// Doublecheck to avoid race condition.
|
||||||
|
if (ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] ==
|
||||||
|
null) {
|
||||||
// Set stream subscription.
|
// Set stream subscription.
|
||||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
|
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin] =
|
||||||
subscription.responseStream.asBroadcastStream().listen((event) {
|
subscription.responseStream.asBroadcastStream().listen((event) {
|
||||||
|
@ -876,15 +879,16 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
level: LogLevel.Error);
|
level: LogLevel.Error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// A subscription already exists.
|
// A subscription already exists.
|
||||||
//
|
//
|
||||||
// Resume the stream subscription if it's paused.
|
// Resume the stream subscription if it's paused.
|
||||||
if (ElectrumxChainHeightService
|
if (ElectrumxChainHeightService
|
||||||
.subscriptions[cryptoCurrency.coin]!.isPaused) {
|
.subscriptions[cryptoCurrency.coin]!.isPaused) {
|
||||||
// If it's paused, resume it.
|
// If it's paused, resume it.
|
||||||
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!
|
ElectrumxChainHeightService.subscriptions[cryptoCurrency.coin]!.resume();
|
||||||
.resume();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Causes synchronization to stall.
|
// Causes synchronization to stall.
|
||||||
|
@ -913,7 +917,6 @@ mixin ElectrumXInterface<T extends Bip39HDCurrency> on Bip39HDWallet<T> {
|
||||||
// Retry/recurse.
|
// Retry/recurse.
|
||||||
return await _manageChainHeightSubscription();
|
return await _manageChainHeightSubscription();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the subscription has been running for too long.
|
// Check if the subscription has been running for too long.
|
||||||
if (ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] != null) {
|
if (ElectrumxChainHeightService.timeStarted[cryptoCurrency.coin] != null) {
|
||||||
|
|
Loading…
Reference in a new issue