Search code examples
erlangerlang-otpgen-server

what is the difference between gen_server:cast to gen_server:abcast


When looking at abcast abcast man page,
and cast cast man page, I couldn't understand what's the difference between those two.
Can someone clarify this to me.

Thanks


Solution

  • There are three differences between gen_server:cast/2 and gen_server:abcast/2,3:

    • gen_server:abcast/3 takes a list of target nodes specifying where gen_server instances registered by the specified name might be found, while gen_server:abcast/2 sends to the list [node() | nodes()], whereas gen_server:cast/2 can address only a single gen_server instance.
    • To identify the target server, gen_server:abcast/2,3 takes only a name, as an atom, whereas gen_server:cast/2 can take an atom, a pid, or for the global and via options, any Erlang term.
    • gen_server:abcast/2,3 returns abcast, whereas gen_server:cast/2 returns ok.

    The first difference is the most important, as it allows for an asynchronous broadcast (i.e., abcast) to a set of gen_server instances across a set of nodes.