package governance import "sync" // SetupSignal reports that the owner setup transaction has committed. The // composition root waits on it instead of polling the database for the change, // and it fires once however many callers ask. type SetupSignal struct { once sync.Once done chan struct{} } // NewSetupSignal returns a signal for a setup that has not committed yet. func NewSetupSignal() *SetupSignal { return &SetupSignal{done: make(chan struct{})} } // Complete records the commit. A second call, sequential or concurrent, // changes nothing. A nil signal is a module built without durable state, as // the API document is, and records nothing. func (s *SetupSignal) Complete() { if s == nil { return } s.once.Do(func() { close(s.done) }) } // Done is closed once the setup has committed. func (s *SetupSignal) Done() <-chan struct{} { if s == nil { return nil } return s.done }