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
|
||||
|
||||
import "time"
|
||||
|
||||
type WebsiteChecker func(string) bool
|
||||
|
||||
func CheckWebsites(wc WebsiteChecker, urls []string) map[string]bool {
|
||||
results := make(map[string]bool)
|
||||
|
||||
for _, url := range urls {
|
||||
go func() {
|
||||
results[url] = wc(url)
|
||||
}()
|
||||
go func(u string) {
|
||||
results[u] = wc(u)
|
||||
}(url)
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
return results
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user