Skip to content

Instantly share code, notes, and snippets.

@kachayev
Last active December 20, 2015 14:19
Show Gist options
  • Save kachayev/6145771 to your computer and use it in GitHub Desktop.
Save kachayev/6145771 to your computer and use it in GitHub Desktop.
main() ->
Clients = ch:make(),
spawn(clients_generator, [Clients]),
lists:foreach(fun(_) ->
spawn(barber, [Clients])
end, lists:seq(1,10)).
clients_generator(Clients) ->
ch:enqueue(client, Clients),
timer:sleep(random:uniform(100)),
clients_generator(Clients).
barber(Clients) ->
ch:foreach(fun(_) ->
timer:sleep(100)
end, Clients).
%% buffer for waiting room?
Clients = ch:buffer(?MAX_WAITERS, ch:make())
%% max clients restrictions for each barber?
ch:foreach(fun(_) -> timer:sleep(100) end,
ch:take(?MAX_CLIENTS, Clients)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment