File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ public class ConnectionManager<RequestHandlerType: RequestHandler>
4141 public var isStarted = false
4242
4343 private var connections = [ Connection] ( )
44+ private let connectionsLock = NSLock ( )
4445
4546 public init ( requestHandler: RequestHandlerType , connectionHandlers: [ ConnectionHandler ] )
4647 {
@@ -88,6 +89,9 @@ private extension ConnectionManager
8889{
8990 func prepare( _ connection: Connection )
9091 {
92+ self . connectionsLock. lock ( )
93+ defer { self . connectionsLock. unlock ( ) }
94+
9195 guard !self . connections. contains ( where: { $0 === connection } ) else { return }
9296 self . connections. append ( connection)
9397
@@ -96,6 +100,9 @@ private extension ConnectionManager
96100
97101 func disconnect( _ connection: Connection )
98102 {
103+ self . connectionsLock. lock ( )
104+ defer { self . connectionsLock. unlock ( ) }
105+
99106 guard let index = self . connections. firstIndex ( where: { $0 === connection } ) else { return }
100107 self . connections. remove ( at: index)
101108 }
You can’t perform that action at this time.
0 commit comments