public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions?options = null) { //sanity check for deferred bootstrapping errors _bucket.ThrowIfBootStrapFailed(); //Get the collection ID await PopulateCidAsync().ConfigureAwait(false); options ??= IncrementOptions.Default; using var rootSpan = RootSpan(OuterRequestSpans.ServiceSpan.Kv.Increment); using var op = new Increment(_bucket.Name, id) { Cid = Cid, CName = Name, SName = ScopeName, Delta = options.DeltaValue, Initial = options.InitialValue, DurabilityLevel = options.DurabilityLevel, Span = rootSpan, Expires = options.ExpiryValue.ToTtl() }; _operationConfigurator.Configure(op, options); using var cts = CreateRetryTimeoutCancellationTokenSource(options, op, out var tokenPair); await _bucket.RetryAsync(op, tokenPair).ConfigureAwait(false); return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken)); }
private void Update(EvaluationContext context) { if (!_initialized || TriggerReset.GetValue(context)) { Result.Value = DefaultValue.GetValue(context); _initialized = true; } var triggered = Running.GetValue(context); if (OnlyCountChanges.GetValue(context) && triggered == _lastTrigger) { return; } _lastTrigger = triggered; if (triggered) { Result.Value += Increment.GetValue(context); } var modulo = Modulo.GetValue(context); if (modulo != 0) { Result.Value %= modulo; } }
public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions options) { using (var op = new Increment { Cid = Cid, Key = id, Delta = options.Delta, Initial = options.Initial, DurabilityLevel = options.DurabilityLevel }) { await ExecuteOp(op, options.Token, options.Timeout); return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken)); } }
public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions?options = null) { //sanity check for deferred bootstrapping errors _bucket.ThrowIfBootStrapFailed(); options ??= new IncrementOptions(); using var op = new Increment(_bucket.Name, id) { Cid = Cid, Delta = options.DeltaValue, Initial = options.InitialValue, DurabilityLevel = options.DurabilityLevel, Transcoder = _transcoder }; await _bucket.SendAsync(op, options.TokenValue, options.TimeoutValue).ConfigureAwait(false); return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken)); }
public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions options = null) { options = options ?? new IncrementOptions(); using (var op = new Increment { Cid = Cid, Key = id, Delta = options.Delta, Initial = options.Initial, DurabilityLevel = options.DurabilityLevel, Transcoder = _transcoder }) { await _bucket.SendAsync(op, options.Token, options.Timeout); return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken)); } }
public async Task <ICounterResult> IncrementAsync(string id, IncrementOptions?options = null) { //sanity check for deferred bootstrapping errors _bucket.ThrowIfBootStrapFailed(); options ??= new IncrementOptions(); using var rootSpan = RootSpan(OperationNames.Increment); using var op = new Increment(_bucket.Name, id) { Cid = Cid, CName = Name, Delta = options.DeltaValue, Initial = options.InitialValue, DurabilityLevel = options.DurabilityLevel, Span = rootSpan, Expires = options.ExpiryValue.ToTtl() }; _operationConfigurator.Configure(op, options); await RetryUntilTimeoutOrSuccessAsync(options.TokenValue, options.TimeoutValue, op).ConfigureAwait(false); return(new CounterResult(op.GetValue(), op.Cas, null, op.MutationToken)); }
private void Update(EvaluationContext context) { var startPosition = StartValue.GetValue(context); var modulo = Modulo.GetValue(context); var increment = Increment.GetValue(context); _rate = Rate.GetValue(context); _phase = Phase.GetValue(context); _blending = Blending.GetValue(context); var reset = TriggerReset.GetValue(context); var jump = TriggerCount.GetValue(context); //var jump = false; if (!_initialized || reset || float.IsNaN(_count)) { _count = 0; _initialized = true; jump = true; } _beatTime = EvaluationContext.BeatTime; if (UseRate) { var activationIndex = (int)(_beatTime * _rate + _phase); if (activationIndex != _lastActivationIndex) { //Log.Debug($"ai {activationIndex} != {_lastActivationIndex} rate={_rate} t = {_beatTime} "); _lastActivationIndex = activationIndex; jump = true; } } if (jump) { if (modulo > 0.001f) { _jumpStartOffset = _jumpTargetOffset; _jumpTargetOffset += 1; } else { _jumpStartOffset = _count; _jumpTargetOffset = _count + increment; } // if (_jumpTargetOffset > modulo) // { // _count = 0; // _jumpStartOffset = 0; // _jumpTargetOffset = increment; // } _lastJumpTime = _beatTime; } if (_blending >= 0.001) { var t = (Fragment / _blending).Clamp(0, 1); if (SmoothBlending.GetValue(context)) { t = MathUtils.SmootherStep(0, 1, t); } _count = MathUtils.Lerp(_jumpStartOffset, _jumpTargetOffset, t); } else { _count = _jumpTargetOffset; } if (modulo > 0.001f) { Result.Value = (_count % modulo) * increment + startPosition; } else { Result.Value = _count + startPosition; } WasStep.Value = jump; Result.DirtyFlag.Clear(); WasStep.DirtyFlag.Clear(); }