Пример #1
0
        public static async partial Task <CentralManager> NewAsync()
        {
            var instance = new CentralManager();

            var state = await [email protected](
                x => x != CBManagerState.Unknown && x != CBManagerState.Resetting
                );

            return(state switch {
                CBManagerState.Unsupported => throw new Exception("bluetooth unsupported"),
                CBManagerState.Unauthorized => throw new Exception("bluetooth unauthorized"),
                CBManagerState.PoweredOff => throw new Exception("bluetooth powered off"),
                CBManagerState.PoweredOn => instance,
                _ => throw new Exception("unknown state"),
            });
Пример #2
0
 private sealed record Stopper(IDisposable Subscription, CentralManager Central) : IAsyncDisposable