File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,19 @@ import Foundation
2
2
3
3
@objcMembers
4
4
@objc open class PusherChannels : NSObject {
5
- open var channels = [ String: PusherChannel] ( )
5
+ // Access via queue for thread safety if user subscribes/unsubscribes to a channel off the main queue
6
+ // (Concurrent reads are allowed. Writes using `.barrier` so queue waits for completion before continuing)
7
+ private let channelsQueue = DispatchQueue ( label: " com.pusher.pusherswift-channels- \( UUID ( ) . uuidString) " ,
8
+ attributes: . concurrent)
9
+ private var channelsInternal = [ String: PusherChannel] ( )
10
+ open var channels : [ String : PusherChannel ] {
11
+ get {
12
+ return channelsQueue. sync { channelsInternal }
13
+ }
14
+ set {
15
+ channelsQueue. async ( flags: . barrier) { self . channelsInternal = newValue }
16
+ }
17
+ }
6
18
7
19
/**
8
20
Create a new PusherChannel, which is returned, and add it to the PusherChannels list
You can’t perform that action at this time.
0 commit comments