Created
July 5, 2018 01:41
-
-
Save shawn111/7a8f4b4ac68a8130db728a1ea86076c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Limit = 50 | |
func doKojiLatestBuild(worker int, repo string, pkg string, results chan<- string) { | |
build := KojiLatestBuild(repo, pkg) | |
fmt.Println(worker, repo, pkg, ">>", build) | |
results <- build | |
} | |
func KojiListLatestBuilds(repo string) []string { | |
pkgs := KojiListPackages(repo) | |
queue := make(chan string) | |
results := make(chan string, len(pkgs)) | |
// limit worker | |
for worker := 0; worker < Limit; worker++ { | |
go func(worker int) { | |
for work := range queue { | |
doKojiLatestBuild(worker, repo, work, results) // blocking wait for work | |
} | |
}(worker) | |
} | |
for _, pkg := range pkgs { | |
queue <- pkg | |
} | |
close(queue) | |
builds := []string{} | |
for i := 1; i <= len(pkgs); i++ { | |
builds = append(builds, <-results) | |
} | |
return builds | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Limit = 50 | |
func doKojiLatestBuild(worker int, repo string, pkg string, results chan<- string) { | |
build := KojiLatestBuild(repo, pkg) | |
fmt.Println(worker, repo, pkg, ">>", build) | |
results <- build | |
} | |
func KojiListLatestBuilds(repo string) []string { | |
pkgs := KojiListPackages(repo) | |
queue := make(chan string) | |
results := make(chan string, len(pkgs)) | |
// limit worker | |
for worker := 0; worker < Limit; worker++ { | |
go func(worker int) { | |
for work := range queue { | |
doKojiLatestBuild(worker, repo, work, results) // blocking wait for work | |
} | |
}(worker) | |
} | |
for _, pkg := range pkgs { | |
queue <- pkg | |
} | |
close(queue) | |
builds := []string{} | |
for i := 1; i <= len(pkgs); i++ { | |
builds = append(builds, <-results) | |
} | |
return builds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment