concurrency: add timeout, pass the url as argument into goroutine, but still have concurrent write issue
This commit is contained in:
parent
cb8e6d23f3
commit
cd4f6fc6c7
@ -1,14 +1,17 @@
|
|||||||
package concurrency
|
package concurrency
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type WebsiteChecker func(string) bool
|
type WebsiteChecker func(string) bool
|
||||||
|
|
||||||
func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
|
func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
|
||||||
results := make(map[string]bool)
|
results := make(map[string]bool)
|
||||||
|
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
go func() {
|
go func(u string) {
|
||||||
results[url] = wc(url)
|
results[u] = wc(u)
|
||||||
}()
|
}(url)
|
||||||
}
|
}
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user