Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active December 20, 2015 13:19
Show Gist options
  • Save kachayev/6138136 to your computer and use it in GitHub Desktop.
Save kachayev/6138136 to your computer and use it in GitHub Desktop.
Functional approach to deal with "google search" example from Rob Pike talk
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