Skip to content

Commit

Permalink
remove async call of subscribe callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
humdrum committed Mar 28, 2024
1 parent 6cf3cb8 commit e2d3c03
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions Sources/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public enum PresenceSubscriptionType: String {
*
*/
public actor Document {
public typealias SubscribeCallback = (DocEvent, isolated Document) async -> Void
public typealias SubscribeCallback = (DocEvent, isolated Document) -> Void

private let key: DocumentKey
private(set) var status: DocumentStatus
Expand Down Expand Up @@ -530,9 +530,7 @@ public actor Document {

if presenceEvents.contains(event.type) {
if let callback = self.presenceSubscribeCallback[PresenceSubscriptionType.presence.rawValue] {
Task {
await callback(event, self)
}
callback(event, self)
}

if let id = self.changeID.getActorID() {
Expand All @@ -555,17 +553,13 @@ public actor Document {

if isMine {
if let callback = self.presenceSubscribeCallback[PresenceSubscriptionType.myPresence.rawValue] {
Task {
await callback(event, self)
}
callback(event, self)
}
}

if isOthers {
if let callback = self.presenceSubscribeCallback[PresenceSubscriptionType.others.rawValue] {
Task {
await callback(event, self)
}
callback(event, self)
}
}
}
Expand All @@ -587,23 +581,17 @@ public actor Document {
let info = ChangeInfo(message: event.value.message, operations: value, actorID: event.value.actorID)

if let callback = self.subscribeCallbacks[key] {
Task {
await callback(event.type == .localChange ? LocalChangeEvent(value: info) : RemoteChangeEvent(value: info), self)
}
callback(event.type == .localChange ? LocalChangeEvent(value: info) : RemoteChangeEvent(value: info), self)
}
}
}
} else {
if let callback = self.subscribeCallbacks["$"] {
Task {
await callback(event, self)
}
callback(event, self)
}
}
if let callback = self.defaultSubscribeCallback {
Task {
await callback(event, self)
}
callback(event, self)
}
}
}
Expand Down

0 comments on commit e2d3c03

Please sign in to comment.