private void Toggle(bool primary) { lock (_sync) { _state = primary ? ImmutableState.Primary(this) : ImmutableState.Secondary(this); } }
public AddressSwitcher(string primaryUrl, string secondaryUrl, TimeSpan timeframe, ITime time) { _primaryUrl = primaryUrl; _secondaryUrl = secondaryUrl; _timeframe = timeframe; _time = time; _sync = new object(); _state = ImmutableState.Primary(this); }
public IState GetState() { lock (_sync) { var state = _state; if (state.ValidUntil > _time.Now) { return(state); } state = _state = ImmutableState.Primary(this); return(state); } }