Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thiebaud committed May 25, 2018
1 parent ad6e022 commit 0d25ef8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Sources/SwiftGRPC/Core/Channel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public class Channel {
}

deinit {
connectivityObservers.forEach { $0.shutdown() }
cgrpc_channel_destroy(underlyingChannel)
completionQueue.shutdown()
}
Expand Down Expand Up @@ -101,8 +102,7 @@ public class Channel {
///
/// - Parameter callback: block executed every time a new connectivity state is detected
public func subscribe(callback: @escaping (ConnectivityState) -> Void) {
let observer = ConnectivityObserver(underlyingChannel: underlyingChannel, currentState: connectivityState(), callback: callback)
connectivityObservers.append(observer)
connectivityObservers.append(ConnectivityObserver(underlyingChannel: underlyingChannel, currentState: connectivityState(), callback: callback))
}
}

Expand All @@ -124,15 +124,13 @@ private extension Channel {
}

deinit {
completionQueue.shutdown()
shutdown()
}

private func run() {
let spinloopThreadQueue = DispatchQueue(label: "SwiftGRPC.ConnectivityObserver.run.spinloopThread")

spinloopThreadQueue.async { [weak self] in
guard let `self` = self else { return }

spinloopThreadQueue.async {
while true {
guard let underlyingState = self.lastState.underlyingState else { return }

Expand All @@ -159,6 +157,10 @@ private extension Channel {
}
}
}

func shutdown() {
completionQueue.shutdown()
}
}
}

Expand Down

0 comments on commit 0d25ef8

Please sign in to comment.