diff --git a/intro_actors/lib/genserver_example.ex b/intro_actors/lib/genserver_example.ex index 81d588e..f8766e0 100644 --- a/intro_actors/lib/genserver_example.ex +++ b/intro_actors/lib/genserver_example.ex @@ -6,7 +6,7 @@ defmodule Post do GenServer.start(__MODULE__, state, name: name) end - def start_link(state, name) do + def start_link(state, name) do GenServer.start_link(__MODULE__, state, name: name) end @@ -28,8 +28,8 @@ defmodule Post do # --- funciones de uso --- - def like(post) do - GenServer.cast(post, {:like, self}) + def like(post, pid) do + GenServer.cast(post, {:like, pid}) end def get_likes(post) do @@ -37,21 +37,15 @@ defmodule Post do end end -#{:ok, post} = Post.start_link(0) -#post = pid_del_actor -#GenServer.call(Post, :get) -#GenServer.cast(Post, :like) +#{:ok, post} = Post.start_link(0, :post_principal) #for _ <- 1..1000, do: Post.like(:post_principal) - -# recibir_like = fn -> Post.get_likes(:post_) end -# aumentar_like = fn -> Post.like(Post) end - - - # aumentar_like = fn -> for _ <- 1..1000, do # Post.like(:post_principal) # :timer.sleep(50) # end # end -# pid_aumentar = spawn aumentar_like \ No newline at end of file +#GenServer.call(Post, :get) +#GenServer.cast(Post, :like, self) +# recibir_like = fn -> Post.get_likes(:post_) end +# aumentar_like = fn -> Post.like(Post) end diff --git a/intro_actors/lib/intro_task.ex b/intro_actors/lib/intro_task.ex index 85ff335..113449c 100644 --- a/intro_actors/lib/intro_task.ex +++ b/intro_actors/lib/intro_task.ex @@ -12,11 +12,6 @@ defmodule IASC.WriteHaiku do Task.start_link(__MODULE__, :read_haiku, []) end - def run(content) do - check_and_create - write_haiku(content) - end - @doc """ Escribe en el archivo """ @@ -40,6 +35,10 @@ defmodule IASC.WriteHaiku do end end + def run(content) do + check_and_create() + write_haiku(content) + end end # {:ok, pid} = IASC.WriteHaiku.start_link_read() diff --git a/intro_actors/lib/receive_example.ex b/intro_actors/lib/receive_example.ex index 647c7dc..54d7611 100644 --- a/intro_actors/lib/receive_example.ex +++ b/intro_actors/lib/receive_example.ex @@ -7,4 +7,4 @@ bloque = fn -> IO.puts 'La tarea de pepita ha terminado' end -pid = spawn bloque \ No newline at end of file +#pid = spawn bloque \ No newline at end of file