Last active
December 19, 2015 04:59
-
-
Save jschoch/5901429 to your computer and use it in GitHub Desktop.
oddness
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
defmodule TF do | |
use GenServer.Behaviour | |
def start_link do | |
:gen_server.start_link({:local,:tf},__MODULE__,nil,[]) | |
end | |
def throttle do | |
IO.puts "Starting at #{inspect :erlang.time}" | |
:gen_server.call :tf, :throttle | |
IO.puts "ending at #{inspect :erlang.time}" | |
end | |
def handle_call(:throttle,_from,state) do | |
:timer.sleep(1000) | |
{:reply,:ok,state} | |
end | |
def work_it do | |
lc x inlist [1,2,3,4,5] do | |
spawn(TF,:throttle,[]) | |
end | |
end | |
def init do | |
{:ok, []} | |
end | |
end | |
output | |
iex(51)> TF.start_link | |
{:ok,#PID<0.375.0>} | |
iex(52)> TF.work_it | |
[#PID<0.376.0>,#PID<0.377.0>,#PID<0.378.0>,#PID<0.379.0>,#PID<0.380.0>] | |
Starting at {15,9,51} | |
Starting at {15,9,51} | |
Starting at {15,9,51} | |
Starting at {15,9,51} | |
Starting at {15,9,51} | |
ending at {15,9,52} | |
ending at {15,9,53} | |
ending at {15,9,54} | |
ending at {15,9,55} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
defmodule TF do
use GenServer.Behaviour
def throttle do
IO.puts "Starting at #{inspect :erlang.time}"
:gen_server.call :s, :throttle
IO.puts "ending at #{inspect :erlang.time}"
end
def handle_call(:throttle,_from,state) do
:timer.sleep(1000)
{:reply,:ok,state}
end
def work_it do
lc x inlist [1,2,3,4,5] do
spawn(TF,:throttle,[])
end
end
end
output
iex(45)> TF.work_it
[#PID<0.351.0>,#PID<0.352.0>,#PID<0.353.0>,#PID<0.354.0>,#PID<0.355.0>]
Starting at {14,48,50}
Starting at {14,48,50}
Starting at {14,48,50}
Starting at {14,48,50}
Starting at {14,48,50}
ending at {14,48,51}
ending at {14,48,52}
ending at {14,48,53}
ending at {14,48,54}