protected Task WaitForState(AblyRealtime realtime, ConnectionState awaitedState = ConnectionState.Connected, TimeSpan?waitSpan = null) { var connectionAwaiter = new ConnectionAwaiter(realtime.Connection, awaitedState); if (waitSpan.HasValue) { return(connectionAwaiter.Wait(waitSpan.Value)); } return(connectionAwaiter.Wait()); }
internal static Task <TimeSpan> WaitForState(this AblyRealtime realtime, ConnectionState awaitedState, TimeSpan?waitSpan = null) { if (realtime.Connection.State == awaitedState) { return(Task.FromResult(TimeSpan.Zero)); } var connectionAwaiter = new ConnectionAwaiter(realtime.Connection, awaitedState); if (waitSpan.HasValue) { return(connectionAwaiter.Wait(waitSpan.Value)); } return(connectionAwaiter.Wait()); }