397
prec []Constraints,
398
callback func(T),
400
>
c.subscriptionLock.Lock()
401
>
defer c.subscriptionLock.Unlock()
402
>
403
>
// get one value immediately (note that subscriptionLock is held here so we can't race with
404
>
// an update)
405
>
cvs := c.client.GetValue(key)
406
>
init, raw := matchAndConvertCvs(c, key, def, convert, prec, cvs)
407
>
408
>
// As a convenience (and for efficiency), you can pass in a nil callback; we just return the
409
>
// current value and skip the subscription. The cancellation func returned is also nil.
410
>
if callback == nil {
411
return init, nil
412
}
413
415
>
id := c.subscriptionIdx
416
>
417
>
if c.subscriptions[key] == nil {
418
>
c.subscriptions[key] = make(map[int]any)
419
>
}
420
422
>
prec: prec,
423
>
f: callback,
424
>
def: def,
425
>
raw: raw,
426
>
}
427
>
428
>
return init, func() {
429
c.subscriptionLock.Lock()
430
defer c.subscriptionLock.Unlock()