Exemple #1
0
func (s *settingsMap) SetHook(name string, hook func(...interface{})) event.Connection {
	s.mutex.Lock()
	defer s.mutex.Unlock()

	if hook == nil {
		panic("received nil hook function")
	}
	ev, ok := s.hooks[name]
	if !ok {
		ev = event.New(false)
		s.hooks[name] = ev
	}
	return ev.Connect(hook)
}
Exemple #2
0
func (ac *Controller) OnUpdate(listener func(...interface{})) event.Connection {
	if ac.onUpdate == nil {
		ac.onUpdate = event.New(true)
	}
	return ac.onUpdate.Connect(listener)
}
Exemple #3
0
// OnProgress is an event that is fired when progress has been made on the
// download. Four arguments are passed to the listener:
//
// `name`: A string identifying the item being downloaded.
//
// `progress`: An int64 indicating the amount of bytes downloaded so far.
//
// `total`: An int64 indicating the total size of the download. This may be
// -1, indicating an unknown size.
//
// `err`: An error, if one has occurred. If the download is finished, the
// error will be io.EOF. If the download was closed before it was finished,
// the error will be ErrClosed.
func (dl *Download) OnProgress(listener func(...interface{})) event.Connection {
	if dl.onProgress == nil {
		dl.onProgress = event.New(false)
	}
	return dl.onProgress.Connect(listener)
}