Last active
December 20, 2015 13:19
-
-
Save kachayev/6138136 to your computer and use it in GitHub Desktop.
Functional approach to deal with "google search" example from Rob Pike talk
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
search(Ch, Kind, Query) -> | |
timer:sleep(random:uniform(100) + 10), | |
enqueue(Ch, {Kind, Query}). | |
fake(Kind) -> | |
Ch = make(), | |
fun(Query) -> | |
spawn(?MODULE, search, [Ch, Kind, Query]), Ch | |
end. | |
fastest(Query, Replicas) -> | |
Chs = lists:map(fun(R) -> R(Query) end, Replicas), | |
read(zip(Chs)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment