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