440
prec []Constraints,
441
callback func(T),
443
>
c.subscriptionLock.Lock()
444
>
defer c.subscriptionLock.Unlock()
445
>
446
>
// get one value immediately (note that subscriptionLock is held here so we can't race with
447
>
// an update)
448
>
cvs := c.client.GetValue(key)
449
>
init, raw := findAndResolveWithConstrainedDefaults(c, key, convert, cvs, cdef, prec)
450
>
451
>
// As a convenience (and for efficiency), you can pass in a nil callback; we just return the
452
>
// current value and skip the subscription. The cancellation func returned is also nil.
453
>
if callback == nil {
454
return init, nil
455
}
456
458
>
id := c.subscriptionIdx
459
>
460
>
if c.subscriptions[key] == nil {
461
>
c.subscriptions[key] = make(map[int]any)
462
>
}
463
465
>
prec: prec,
466
>
f: callback,
467
>
cdef: cdef,
468
>
raw: raw,
469
>
}
470
>
471
>
return init, func() {
472
c.subscriptionLock.Lock()
473
defer c.subscriptionLock.Unlock()