fix crash when adding line to log from background thread
Signed-off-by: Bryan Montz <bryanmontz@me.com> Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
committed by
William Casarin
parent
51d71f11c1
commit
2d9f7128ee
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user