func (o *Observable) Subscribe(ctx context.Context, write func(v interface{})) {
	o.mtx.Lock()
	defer o.mtx.Unlock()
	if o.val != nil {
		write(o.val)
	}
	o.subs = append(o.subs, &obsSub{
		isCanceled: func() bool {
			select {
			case <-ctx.Done():
				return true
			default:
				return false
			}
		},
		emitValue: write,
	})
}
Subscribe subscribes to the value.
package resolver
import (
	"context"
	"sync"
)
type Observable struct {
	mtx  sync.Mutex
	val  interface{}
	subs []*obsSub
}
type obsSub struct {
	isCanceled func() bool
	emitValue  func(v interface{})
}
func NewObservable(val interface{}) *Observable {
	return &Observable{val: val}
}
func (o *Observable) Set(val interface{}) {
	o.mtx.Lock()
	defer o.mtx.Unlock()
	o.val = val
	for i := 0; i < len(o.subs); i++ {
		sub := o.subs[i]
		if sub.isCanceled() {
			o.subs[i] = o.subs[len(o.subs)-1]
			o.subs[len(o.subs)-1] = nil
			o.subs = o.subs[:len(o.subs)-1]
			i--
			continue
		}
		sub.emitValue(val)
	}
}
func (o *Observable) Get() interface{} {
	o.mtx.Lock()
	defer o.mtx.Unlock()
	return o.val
}