Search code examples
erlangerlang-otpgen-server

gen server synchronous and asynchronous calls


Suppose I have a gen_server that is handling only asynch calls (thus only handle_cast is implemented), should i keep handle_call and make it return only the generic ok value, or should i remove that part of the code and accept the warnings?


Solution

  • I'd opt for always returning {reply, ok, State}. Treat warnings as errors (that is, stop compilation and fix them). That way, when real warnings appear, they aren't hidden behind the noise.

    It's a good habit to wrap all calls to behaviors in your own function, e.g:

    delete(Something) ->
        gen_server:call(?MODULE, {delete, Something}).
    

    In this case, don't export any function which uses handle_call/2.