Last active
April 8, 2018 11:20
-
-
Save just1689/76d24dc3801a2c47df1c6086b1c76a70 to your computer and use it in GitHub Desktop.
Query multiple sources at once - return first
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
func Query(conns []Conn, query string) Result { | |
ch := make(chan Result) | |
for _, conn := range conns { | |
go func(c Conn) { | |
select { | |
case ch <- c.DoQuery(query): | |
default: | |
} | |
}(conn) | |
} | |
return <-ch | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment