Exemple #1
0
// do executes the passed function for all connected cells
// and collects potential errors.
func (cs *connections) do(f func(c *cell) error) error {
	cs.mutex.RLock()
	defer cs.mutex.RUnlock()
	var errs []error
	for _, csc := range cs.cells {
		if err := f(csc); err != nil {
			errs = append(errs, err)
		}
	}
	switch len(errs) {
	case 0:
		return nil
	case 1:
		return errs[0]
	default:
		return errors.Collect(errs...)
	}
}
Exemple #2
0
// do executes the passed function for all subscriber cells
// and collects potential errors.
func (s *subscribers) do(f func(s Subscriber) error) error {
	s.mutex.RLock()
	defer s.mutex.RUnlock()
	var errs []error
	for _, sc := range s.cells {
		if err := f(sc); err != nil {
			errs = append(errs, err)
		}
	}
	switch len(errs) {
	case 0:
		return nil
	case 1:
		return errs[0]
	default:
		return errors.Collect(errs...)
	}
}