Erlang gen_server vs factorless module

I recently finished a book by Joe and enjoyed it. I have since started coding a soft real-time application with erlang, and I have to say that I'm a bit confused about using gen_server.

When should gen_server be used instead of a simple stateless module? I define a stateless module as follows: - A module that takes it as a parameter (like ETS / DETS), and not internally (like gen_server)

Tell me for a module such as an invoice manager, should it initialize and return the state that I would then pass on to it? SomeState = InvoiceManager: Init (), SomeState = InvoiceManager: AddInvoice (SomeState, AnInvoiceFoo).

Suppose I need several instances of the state of an account manager (for example, my application manages several companies each with their own invoices), should they have a gene server with an internal state to manage their accounts or would it be better to correspond to the simple stateless module above ?

Where is the line between the two?

(Please note that the above account management example is an example illustrating my question)

+3
source share
5 answers

. , . gen_server, gen_fsm gen_* - . , , . , . "" . " " - ( ). gen_server , "". , - ( concurrency).

+2

, , gen_server. , . , , , . , , , API/.

, gen_server . OTP . , , , . , .

, . gen_server "", . , , . , , . ?

+7

, , gen_server . , OTP: gen_server - .

+1

, , , gen_server, , .

+1

I believe that your invoices (or what they mean) should be constant, so they will still appear in the ETS / Mnesia table. If so, you should create a stateless module where you put your API to access the table of accounts.

+1
source

Source: https://habr.com/ru/post/1720906/


All Articles