Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 757
Matt. Stroh Avatar asked Jul 04 '16 12:07

Matt. Stroh


People also ask

What is gen_ server?

A gen_server is a specific finite state machine working like a server. gen_server can handle different type of event: synchronous request with handle_call. asynchronous request with handle_cast. other message (not defined in OTP specification) with handle_info.

How do I stop Erlang server?

stop() -> exit(?


1 Answers

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.

like image 125
Steve Vinoski Avatar answered Nov 09 '22 06:11

Steve Vinoski