Coder Social home page Coder Social logo

Comments (4)

sasa1977 avatar sasa1977 commented on September 27, 2024

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}})

from exactor.

Trevoke avatar Trevoke commented on September 27, 2024

from exactor.

sasa1977 avatar sasa1977 commented on September 27, 2024

Normally, defcast and defcall take the server as the first argument, so you can pass the same via tuple as in start_link. That's of course clumsy, because the clients must be aware of the exact shape of the via tuple.

If you want to wrap that knowledge inside the GenServer module, you can use private versions of defcastp and defcallp and wrap them with a plain function:

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.

from exactor.

Trevoke avatar Trevoke commented on September 27, 2024

nod I understand, thank you.

from exactor.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.