-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can this be used with a via_tuple? #26
Comments
You can pass a def MyServer do
defstart start_link(arg1, arg2), gen_server_opts: :runtime do
# ...
end
# ...
end Now, your MyServer.start_link(arg1, arg2, name: {:via, Registry, {MyRegistry, some_name}}) |
I see; and how do use defcast and defcast so I can pass in the name via the
API function?
…On Sat, May 27, 2017, 09:19 Saša Jurić ***@***.***> wrote:
You can pass a gen_server_opts: :runtime to defstart:
def MyServer do
defstart start_link(arg1, arg2), gen_server_opts: :runtime do # ...
end # ...end
Now, your start_link accepts three arguments: arg1, arg2, and GenServer
options, so you can do the following:
MyServer.start_link(arg1, arg2, name: {:via, Registry, {MyRegistry, some_name}})
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEJSavBxK61fGQd0veZrrq-71wqWW3pks5r-D8TgaJpZM4NoPJc>
.
|
Normally, If you want to wrap that knowledge inside the GenServer module, you can use private versions of def MyServer do
def some_op(name, arg1, arg2), do: some_op_cast(via_tuple(name), arg1, arg2)
defcastp some_op_cast(arg1, arg2, ...) do
# ...
end
defp via_tuple(name), do:
{:via, Registry, {MyRegistry, some_name}}
end Unfortunately, at this point ExActor doesn't really give you much compared to plain GenServer. ExActor only helps for the simplest cases where all arguments are passed as is. As soon as you somehow need to transform those arguments, it will be pretty much the same amount of code as with GenServer. This is the reason why I mostly stopped using ExActor myself. It sometimes help, but not always, so it seems to me that using a plain GenServer is generally a better way, because it's less magical and standard part of Elixir. |
nod I understand, thank you. |
I am using Elixir's Registry (though I don't think this matters) to keep track of multiple processes born from the same module all with a different
id
. I'm not sure I can do this cleanly with this package. Is that true, or am I missing the option that allows it? All I saw wasuse ExActor.GenServer, export: {:global, :global_registered_name}
but it doesn't look like it will work if I need to spawn two of this kind of process and give them different names?The text was updated successfully, but these errors were encountered: