Skip to content

Commit

Permalink
Merge pull request #1307 from planetary-social/fix-crash-in-pagedrela…
Browse files Browse the repository at this point in the history
…ysubscription

Probably fix a crash in PagedRelaySubscription
  • Loading branch information
mplorentz authored Jul 17, 2024
2 parents 158e71b + 10c7703 commit 02b7653
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions Nos/Service/Relay/PagedRelaySubscription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,29 @@ class PagedRelaySubscription {
to: relayAddress
)

pagedEventSubscription.events.sink { [weak self] jsonEvent in
self?.track(event: jsonEvent, from: relayAddress)
}
.store(in: &cancellables)
pagedEventSubscription.events
.sink { [weak self] jsonEvent in
Task {
await self?.track(event: jsonEvent, from: relayAddress)
}
}
.store(in: &cancellables)

pagedSubscriptionIDs.insert(pagedEventSubscription.id)
}
}
}

func track(event: JSONEvent, from relay: URL) {
if let oldestSeen = oldestEventByRelay[relay],
func updateOldestEvent(for relay: URL, to date: Date) {
oldestEventByRelay[relay] = date
}

nonisolated func track(event: JSONEvent, from relay: URL) async {
if let oldestSeen = await oldestEventByRelay[relay],
event.createdDate < oldestSeen {
oldestEventByRelay[relay] = event.createdDate
await updateOldestEvent(for: relay, to: event.createdDate)
} else {
oldestEventByRelay[relay] = event.createdDate
await updateOldestEvent(for: relay, to: event.createdDate)
}
}
}

0 comments on commit 02b7653

Please sign in to comment.