murky problem again

This commit is contained in:
Ian Gulliver
2026-10-18 21:54:54 -07:00
parent 41490b2251
commit d02f4c7280
2 changed files with 10 additions and 5 deletions
+9 -4
View File
@@ -61,9 +61,6 @@ final class Servers {
}
func add(_ origin: URL) {
if let connection = connections[origin.absoluteString], case .failed = connection.phase {
connections[origin.absoluteString] = nil
}
if record(origin.absoluteString) == nil {
let used = Set(entries.map(\.record.color))
let color = taskPalette.indices.first { !used.contains($0) } ?? entries.count % taskPalette.count
@@ -140,6 +137,12 @@ final class Connection {
}
private func start() async {
while !stopped, !(await attempt()) {
try? await Task.sleep(for: .seconds(2))
}
}
private func attempt() async -> Bool {
let store = Store(api: API(origin: origin))
do {
let status = try await store.api.client.getStatus().ok.body.json
@@ -153,7 +156,7 @@ final class Connection {
try await store.loadFocus()
guard !stopped else {
await store.stop()
return
return true
}
Task {
await store.startLeadStream()
@@ -162,11 +165,13 @@ final class Connection {
store.startGlobalStream(after: status.lastEventSeq)
store.remote.start()
Notifier.shared.deliver()
return true
} catch {
await store.stop()
if !stopped {
phase = .failed("byre failed to start: \(errorText(error))")
}
return false
}
}
}