Workaround for bizarre compiler crash
@@ -461,16 +461,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
var upToDateListener: AnyCancellable? = nil
var peer: Lightning_kmpPeer? = nil
- var oldChannels: [Bitcoin_kmpByteVector32 : Lightning_kmpChannelState] = [:]
+ var oldChannels = [Bitcoin_kmpByteVector32 : Lightning_kmpChannelState]()
- var isFinished = false
- let finishTask = {(success: Bool) in
-
- let cleanup = {
- if isFinished {
- return
- }
- isFinished = true
+ let cleanup = {(success: Bool) in
if didDecrement { // need to balance decrement call
appConnectionsDaemon?.incrementDisconnectCount(target: electrumTarget)
@@ -521,10 +514,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
task.setTaskCompleted(success: false)
}
- if Thread.isMainThread {
- cleanup()
- } else {
- DispatchQueue.main.async { cleanup() }
+ var isFinished = false
+ let finishTask = {(success: Bool) in
+
+ DispatchQueue.main.async {
+ if !isFinished {
+ isFinished = true
+ cleanup(success)
+ }
}
}
@@ -533,13 +530,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
}
peer = business.getPeer()
- guard let peer = peer else {
+ guard let _peer = peer else {
// If there's not a peer, then the wallet is locked.
return finishTask(true)
}
- oldChannels = peer.channels
-
+ oldChannels = _peer.channels
guard oldChannels.count > 0 else {
// We don't have any channels, so there's nothing to watch.
return finishTask(true)
@@ -551,8 +547,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate {
// We setup a handler so we know when the WatchTower task has completed.
// I.e. when the channel subscriptions are considered up-to-date.
- upToDateListener = peer.watcher.upToDatePublisher().sink { (millis: Int64) in
-
+ upToDateListener = _peer.watcher.upToDatePublisher().sink { (millis: Int64) in
finishTask(true)
}
}
