void Handle(GameLockChanged gameLockChanged) { var obs = GetOrAdd(gameLockChanged.GameId); lock (obs) { var state = new GameLockState(gameLockChanged.IsLocked, gameLockChanged.CanAbort); _currentValues[gameLockChanged.GameId] = state; obs.Item1.OnNext(state); } }
Tuple<Subject<GameLockState>, GameLockState> GetOrAdd(Guid gameId) { lock (_observables) { if (!_observables.ContainsKey(gameId)) { _observables[gameId] = new Subject<GameLockState>(); _currentValues[gameId] = new GameLockState(false, false); } return Tuple.Create(_observables[gameId], _currentValues[gameId]); } }