package reach import ( "sync" "forge.cadoles.com/Pyxis/golang-socketio" "github.com/pkg/errors" ) const ( eventIsReceiverUpgradeAvailable = "is receiver upgrade available" eventReceiverUpgradeAvailable = "receiver upgrade available" ) type receiverUpgreAvailable struct { Available bool `json:"available"` Running bool `json:"running"` } // ReceiverUpgradeAvailable checks if an upgrade is avaialable/running for the ReachRS module func (u *Updater) ReceiverUpgradeAvailable() (available bool, running bool, err error) { var wg sync.WaitGroup wg.Add(1) err = u.conn.On(eventReceiverUpgradeAvailable, func(h *gosocketio.Channel, up *receiverUpgreAvailable) { available = up.Available running = up.Running u.conn.Off(eventReceiverUpgradeAvailable) wg.Done() }) if err != nil { return false, false, errors.Wrapf(err, "error while binding to '%s' event", eventReceiverUpgradeAvailable) } u.logf("sending '%s' event", eventIsReceiverUpgradeAvailable) if err = u.conn.Emit(eventIsReceiverUpgradeAvailable, nil); err != nil { return false, false, errors.Wrapf(err, "error while emitting '%s' event", eventIsReceiverUpgradeAvailable) } u.logf("'%s' event sent", eventIsReceiverUpgradeAvailable) wg.Wait() u.logf("receiver upgrade result: available: %v, running: %v", available, running) return available, running, err }