gen_server:cast/2 vs !

Vance Shipley vances@REDACTED
Sat Oct 4 16:02:29 CEST 2003

The cast call says it always returns ok.  This is different
from bang behaviour:

1> gen_server:cast(self(), foo).
2> self() ! foo.

3> gen_server:cast(pid(0,999,0), foo).
4> pid(0,999,0) ! foo.

5> gen_server:cast(bogus, foo).
6> bogus ! foo.

=ERROR REPORT==== 4-Oct-2003::09:40:56 ===
Error in process <0.33.0> on node 'mapper@REDACTED' with exit value: {badarg,[{erl_eval,eval_op,3},{erl_eval,expr,5},{shell,eval_loop,2}]}

** exited: {badarg,[{erl_eval,eval_op,3},
                    {shell,eval_loop,2}]} **

The latter may well be the preferable behaviour, if the registered
process doesn't exist fail and let supervision restore sanity.

On the other hand if you would otherwise wrap the send in a catch
the cast behaviour is more desirable.


More information about the erlang-questions mailing list