do_initialization() example

Dieter Schön dieter@REDACTED
Fri Jan 1 16:43:12 CET 2021


Dear Peter,

as I see it, this code is just an example that shows how to initialize a 
custom process/module

which adheres to OTP.

The function do_initialization() is just a placeholder and depends on 
the topic of your module.

This could be anything from contacting a database to initializing an I2C 
link.

Here it is only known that it either returns ok or {error, Reason}. 
Based on this, the startup

either succeeds or fails.


In general, if you are looking for examples, I suggest to search on 
github or similar, something like

https://github.com/search?q=proc_lib%3Ainit_ack&type=commits



Kind regards,

Dieter


On 01.01.21 06:32, Peter J Etheridge wrote:
> Dear Fellow Erlangers,
>
> In proc_lib module this example includes a function in the case statement;
>
> -module(my_proc).
> -export([start_link/0]).
> -export([init/1]).
>
> start_link() ->
>      proc_lib:start_link(my_proc, init, [self()])
>
> init(Parent) ->
>      case  do_initialization()of
>          ok ->
>              proc_lib:init_ack(Parent, {ok, self()});
>          {error, Reason} ->
>              exit(Reason)
>      end,
>      loop().
>
>
> could someone kindly direct me to an example of a
>
> do_initialization()
>
> function?
>
> thank you in advance,
>
> Peter
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20210101/caf4dc66/attachment.htm>


More information about the erlang-questions mailing list