Instead of counting and using a done channel,
import "sync"
...
var wg sync.WaitGroup
for ... {
wg.Add(1)
go dowork()
}
wg.Wait()Since the standard libs in Go duplicate code, you would have to be careful that your suggestion system isn't picking up false positives. I think the idea has a lot of promise though.
Something like this would work even better:
result = src.asyncMap { |e| dowork(e) };
Except Google Go returns several values instead of tuples, so you can't just collect all the results as-is. And with no generics it would be annoying to actually use e and the result, since they would need casts. Too bad.> Except Google Go returns several values instead of tuples, so you can't just collect all the results as-is.
This is false. Functions in Go do not have to return multiple values. Therefore, you can "collect all the results as-is".
> And with no generics it would be annoying to actually use e and the result, since they would need casts. Too bad.
Actually, it wouldn't be annoying, because you wouldn't use a general purpose map like you've shown. You'd use code shown in the parent.
while read line; do
host $line | head -n1 | awk '{print $1 " -> " $4}' &
done < domains.txtIf you gnu parallel (xargs++) installed - turn that second line into a script (and replace $line with $1).
cat domains.txt | parallel -n 1 -P 50 script.shFYI: On OSX, there is a Homebrew formula (brew install parallel).
cat domains.txt | parallel -P 100 --tag host | grep 1.2.3.4
Somewhat slower runtime than the go-solution, but may be faster to write. <domains.txt while read line; do
host $line | head -n1 &
done | awk '{print $1 " -> " $4}'Is it the two ", _" things?
file_in, _ := ioutil.ReadFile("domains.txt")
It says call ReadFile. In go a function can return multiple values. ReadFile returns an byte array and an error value. Normally you'd check to see if err is nil, if it is then no error happened. If it isn't you can check it out for information about the error and handle it.
A unique feature about go is that declaring a variable and never using it is an error and not a warning. Actually there aren't even compiler warnings. Either it is right or wrong. This means if he had called:
file_in, err := ioutil.ReadFile("domains.txt")
but never checked err it would not build. So to get the byte array but not the error you use the _ symbol to tell it to throw away that return value. This is what I was on about in that you have to actively ignore error handling if you want a return value.
Ahhh. Nice. That sounds like a feature I could get behind, too. Thank you.