Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang and Singleton good practice?

Since Erlang isnt really object oriented, there is no real singleton class but i guess a process which is registered can be used as one.

Is it good practice to use registered processes for that inside an application to make the access easier? Disadvantage i see that for example that you cannot run more than one instance of such an application inside one node.

Take as example a gui application with a process managing the events and some other responsible for the sound. Would it be good practise to make those 2 "singleton" as registered processes and call them like sound:play(file_name) instead of storing the pid and doing sound:play(Pid, file_name)?

like image 956
Skully Avatar asked Dec 10 '11 22:12

Skully


1 Answers

It is fairly common to use a gen_server under a registered name to do exactly this. You can export functions from that same module which simply do a gen_server:call against the named process in question.

(Arguably, Erlang is more "really" OO than what you're probably used to. But that's not what this question is about.)

like image 63
Justin Sheehy Avatar answered Oct 14 '22 09:10

Justin Sheehy