Skip to content

Commit 8b2e684

Browse files
committed
Fix race conditions in ChatAdapter and remove concurrent queue
1 parent ed86f52 commit 8b2e684

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

Sources/Miscellaneous/ChatAdapter.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import PubNubChat
1313

1414
class ChatAdapter {
1515
private static var associations: [Association] = []
16-
private static let queue = DispatchQueue(label: "ChatAdapter.associations", attributes: .concurrent)
16+
private static let queue = DispatchQueue(label: "ChatAdapter.associations")
1717
private init() {}
1818

1919
static func map(chat: PubNubChat.Chat) -> Association {
@@ -27,15 +27,13 @@ class ChatAdapter {
2727
}
2828

2929
static func associate(chat: ChatImpl, with kotlinChat: PubNubChat.ChatImpl) {
30-
queue.async(flags: .barrier) {
31-
if !associations.contains(where: { !$0.isEmpty() && $0.chat !== chat && $0.kotlinChat !== kotlinChat }) {
32-
associations.append(.init(chat: chat, kotlinChat: kotlinChat))
33-
}
30+
queue.sync {
31+
associations.append(.init(chat: chat, kotlinChat: kotlinChat))
3432
}
3533
}
3634

3735
static func clean() {
38-
queue.async(flags: .barrier) {
36+
queue.sync {
3937
associations.removeAll {
4038
$0.isEmpty()
4139
}

0 commit comments

Comments
 (0)