Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bossiernesto committed May 2, 2024
1 parent df69a0f commit d6d32c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
22 changes: 8 additions & 14 deletions intro_actors/lib/genserver_example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,30 +28,24 @@ 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
GenServer.call(post, :get)
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
#GenServer.call(Post, :get)
#GenServer.cast(Post, :like, self)
# recibir_like = fn -> Post.get_likes(:post_) end
# aumentar_like = fn -> Post.like(Post) end
9 changes: 4 additions & 5 deletions intro_actors/lib/intro_task.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion intro_actors/lib/receive_example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bloque = fn ->
IO.puts 'La tarea de pepita ha terminado'
end

pid = spawn bloque
#pid = spawn bloque

0 comments on commit d6d32c8

Please sign in to comment.