oficina / docs Public

Clone
git clone https://amadan.net/oficina/docs

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import RastrilloApple
3
4/// The transport supplier a window hands its workspace, for one account.
5///
6/// A workspace's model can outlive a session of its account, so it asks for
7/// the connection's current client on every request instead of keeping one.
8/// It must never be handed another account's session, even for a moment:
9/// SwiftUI can still be finishing a request or holding a stream for the old
10/// workspace after the window switches accounts.
11public enum DocsAccountTransport {
12 @MainActor public static func supplier(account: String?,
13 active: @escaping @MainActor () -> String?,
14 client: @escaping @MainActor () -> NativeTransport?) -> @MainActor () -> NativeTransport? {
15 return {
16 // Checked on every request, not when the supplier is made: a
17 // switch can land while a save or stream reconnect is in flight.
18 guard let account, active() == account else { return nil }
19 return client()
20 }
21 }
22}
23