/// <inheritdoc cref="LeaveAsync"/> public Task LeaveAsync(string key, IWebSocketIo webSocketIo) { return(Task.Run(() => { try { _semaphoreSlim.Wait(); if (_channels[key].Contains(webSocketIo)) { _channels[key].Remove(webSocketIo); webSocketIo.JoinedChannels.Remove(key); webSocketIo.OnLeaved(this, new WebSocketIoEventArgs(key, webSocketIo)); if (_channels[key].Count == 0) { _channels.Remove(key); } } } finally { _semaphoreSlim.Release(); } })); }
/// <inheritdoc cref="LeaveAllAsync"/> public Task LeaveAllAsync(IWebSocketIo webSocketIo) { return(Task.Run(() => { try { _semaphoreSlim.Wait(); foreach (var channel in webSocketIo.JoinedChannels) { if (_channels.ContainsKey(channel)) { _channels[channel].Remove(webSocketIo); webSocketIo.OnLeaved(this, new WebSocketIoEventArgs(channel, webSocketIo)); } } webSocketIo.JoinedChannels.Clear(); } finally { _semaphoreSlim.Release(); } })); }