eth/downloader: better ux

This commit is contained in:
Gary Rong 2024-01-22 12:17:30 +08:00
parent aa21c1f2f4
commit 9f13d29432

View file

@ -68,7 +68,7 @@ func (api *DownloaderAPI) eventLoop() {
var ( var (
sub = api.mux.Subscribe(StartEvent{}) sub = api.mux.Subscribe(StartEvent{})
syncSubscriptions = make(map[chan interface{}]struct{}) syncSubscriptions = make(map[chan interface{}]struct{})
checkInterval = time.Second * 30 checkInterval = time.Second * 60
checkTimer = time.NewTimer(checkInterval) checkTimer = time.NewTimer(checkInterval)
// status flags // status flags
@ -102,15 +102,6 @@ func (api *DownloaderAPI) eventLoop() {
} }
switch event.Data.(type) { switch event.Data.(type) {
case StartEvent: case StartEvent:
prog := getProgress()
notification := &SyncingResult{
Syncing: true,
Status: prog,
}
// broadcast
for c := range syncSubscriptions {
c <- notification
}
started = true started = true
} }
case <-checkTimer.C: case <-checkTimer.C:
@ -120,6 +111,13 @@ func (api *DownloaderAPI) eventLoop() {
} }
prog := getProgress() prog := getProgress()
if !prog.Done() { if !prog.Done() {
notification := &SyncingResult{
Syncing: true,
Status: prog,
}
for c := range syncSubscriptions {
c <- notification
}
checkTimer.Reset(checkInterval) checkTimer.Reset(checkInterval)
continue continue
} }