// Executes traverseDependenciesFunc on all dependencies in dependenciesMap. Each dependency that gets true in return, is added to dependenciesList.
Executes traverseDependenciesFunc on all dependencies in dependenciesMap. Each dependency that gets true in return, is added to dependenciesList.
// Executes traverseDependenciesFunc on all dependencies in dependenciesMap . Each dependency that gets true in return is added to dependenciesList .
func TraverseDependencies(dependenciesMap map[string]*entities.Dependency, traverseDependenciesFunc func(dependency *entities.Dependency) (bool, error), threads int) (dependenciesList []entities.Dependency, err error) {
	producerConsumer := parallel.NewBounedRunner(threads, false)
	dependenciesChan := make(chan *entities.Dependency)
	errorChan := make(chan error, 1)
	go func() {
		defer producerConsumer.Done()
		for _, dep := range dependenciesMap {
			handlerFunc := createHandlerFunc(dep, dependenciesChan, traverseDependenciesFunc)
			_, err = producerConsumer.AddTaskWithError(handlerFunc, func(err error) {
				select {
				case errorChan <- err:
				default:
					return
				}
			})
			if err != nil {
				return
			}
		}
	}()
	var wg sync.WaitGroup
	wg.Add(1)
	go func() {
		for dep := range dependenciesChan {
			dependenciesList = append(dependenciesList, *dep)
		}
		wg.Done()
	}()
	producerConsumer.Run()
	if err != nil {
		return
	}
	close(dependenciesChan)
	wg.Wait()
	select {
	case err = <-errorChan:
	default:
		return
	}
	return
}
func TraverseDependencies ( dependenciesMap map [ string ] * entities . Dependency , traverseDependenciesFunc func ( dependency * entities . Dependency ) ( bool , error ) , threads int ) ( dependenciesList [ ] entities . Dependency , err error ) { producerConsumer := parallel . NewBounedRunner ( threads , false ) dependenciesChan := make ( chan * entities . Dependency ) errorChan := make ( chan error , 1 ) go func ( ) { defer producerConsumer . Done ( ) for _ , dep := range dependenciesMap { handlerFunc := createHandlerFunc ( dep , dependenciesChan , traverseDependenciesFunc ) _ , err = producerConsumer . AddTaskWithError ( handlerFunc , func ( err error ) { select { case errorChan <- err : default : return } } ) if err != nil { return } } } ( ) var wg sync . WaitGroup wg . Add ( 1 ) go func ( ) { for dep := range dependenciesChan { dependenciesList = append ( dependenciesList , * dep ) } wg . Done ( ) } ( ) producerConsumer . Run ( ) if err != nil { return } close ( dependenciesChan ) wg . Wait ( ) select { case err = <- errorChan : default : return } return }
Executes traverseDependenciesFunc on all dependencies in dependenciesMap.
Executes traverseDependenciesFunc on all dependencies in dependenciesMap .
// Write the error to the channel, but don't wait if the channel buffer is full. // Read the error from the channel, but don't wait if the channel buffer is empty.