From 2d9f7128eec6733062e23f6ada082402b55953c9 Mon Sep 17 00:00:00 2001 From: Bryan Montz Date: Sun, 9 Jul 2023 08:45:39 -0500 Subject: [PATCH] fix crash when adding line to log from background thread Signed-off-by: Bryan Montz Signed-off-by: William Casarin --- damus/Nostr/RelayLog.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/damus/Nostr/RelayLog.swift b/damus/Nostr/RelayLog.swift index 035af723..6471ddc4 100644 --- a/damus/Nostr/RelayLog.swift +++ b/damus/Nostr/RelayLog.swift @@ -81,15 +81,18 @@ final class RelayLog: ObservableObject { /// Adds content to the log /// - Parameter content: what to add to the log. The date and time are prepended to the content. func add(_ content: String) { - let line = "\(formatter.string(from: .now)) - \(content)" - lines.insert(line, at: 0) - truncateLines() - Task { + await addLine(content) await publishChanges() } } + @MainActor private func addLine(_ line: String) { + let line = "\(formatter.string(from: .now)) - \(line)" + lines.insert(line, at: 0) + truncateLines() + } + /// Tells views that our log has been updated @MainActor private func publishChanges() { objectWillChange.send()