Beispiel #1
0
// Callback is the callback, used to update the progress bar as remote.cache
// downloads
func (cb *CacheCallback) Callback(par *dnode.Partial) {
	type Progress struct {
		Progress int        `json:progress`
		Error    kite.Error `json:error`
	}

	// TODO: Why is this an array from Klient? How can this be written cleaner?
	ps := []Progress{{}}
	par.MustUnmarshal(&ps)
	p := ps[0]

	cb.Log.Debug("CacheCallback Progress: %#v", p)

	if p.Error.Message != "" {
		cb.doneErr <- p.Error
	}

	cb.Bar.Set(p.Progress)

	// TODO: Disable the callback here, so that it's impossible to double call
	// the progress after competion - to avoid weird/bad UX and errors.
	if p.Progress == 100 {
		cb.doneErr <- nil
	}
}