MCPcopy Create free account
hub / github.com/erpc/erpc / TryUpdate

Method TryUpdate

data/shared_state_variable.go:364–388  ·  view source on GitHub ↗
(ctx context.Context, newValue int64)

Source from the content-addressed store, hash-verified

362}
363
364func (c *counterInt64) TryUpdate(ctx context.Context, newValue int64) int64 {
365 ctx, span := common.StartSpan(ctx, "CounterInt64.TryUpdate",
366 trace.WithAttributes(
367 attribute.String("key", c.key),
368 ),
369 )
370 defer span.End()
371 if common.IsTracingDetailed {
372 span.SetAttributes(
373 attribute.Int64("new_value", newValue),
374 )
375 }
376 // IMPORTANT: TryUpdate must never wait on updateMu.
377 // updateMu exists to coordinate expensive refresh execution in TryUpdateIfStale (thundering herd control),
378 // but local counter advancement must remain fast even if a refresh is in-flight.
379 updated := c.processNewValue(UpdateSourceTryUpdate, newValue)
380
381 // Schedule background push when value was actually updated (increase OR decrease).
382 // With unified semantics, all value changes are propagated to remote.
383 // Note: Value can be 0 for valid cases like earliest block = genesis.
384 if updated {
385 c.scheduleBackgroundPushCurrent()
386 }
387 return c.value.Load()
388}
389
390func (c *counterInt64) TryUpdateIfStale(ctx context.Context, staleness time.Duration, executeNewValueFn func(ctx context.Context) (int64, error)) (int64, error) {
391 ctx, span := common.StartSpan(ctx, "CounterInt64.TryUpdateIfStale",

Calls 7

processNewValueMethod · 0.95
StartSpanFunction · 0.92
EndMethod · 0.80
SetAttributesMethod · 0.80
LoadMethod · 0.80
StringMethod · 0.45