50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package reach
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"forge.cadoles.com/Pyxis/golang-socketio"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const (
|
|
eventGetTimeSyncStatus = "get time sync status"
|
|
eventTimeSyncResults = "time sync status"
|
|
)
|
|
|
|
type timeSyncStatus struct {
|
|
Status bool `json:"status"`
|
|
}
|
|
|
|
// TimeSyncStatus returns the ReachRS module time sync status
|
|
func (u *Updater) TimeSyncStatus() (bool, error) {
|
|
|
|
var err error
|
|
var synced bool
|
|
var wg sync.WaitGroup
|
|
|
|
wg.Add(1)
|
|
|
|
err = u.conn.On(eventTimeSyncResults, func(h *gosocketio.Channel, st *timeSyncStatus) {
|
|
synced = st.Status
|
|
u.conn.Off(eventTimeSyncResults)
|
|
wg.Done()
|
|
})
|
|
if err != nil {
|
|
return false, errors.Wrapf(err, "error while binding to '%s' event", eventTimeSyncResults)
|
|
}
|
|
|
|
u.logf("sending '%s' event", eventGetTimeSyncStatus)
|
|
if err = u.conn.Emit(eventGetTimeSyncStatus, nil); err != nil {
|
|
return false, errors.Wrapf(err, "error while emitting '%s' event", eventGetTimeSyncStatus)
|
|
}
|
|
u.logf("'%s' event sent", eventGetTimeSyncStatus)
|
|
|
|
wg.Wait()
|
|
|
|
u.logf("time sync result: %v", synced)
|
|
|
|
return synced, err
|
|
|
|
}
|