[erlang-questions] initializing process

Gleb Peregud gleber.p@REDACTED
Thu Sep 17 17:58:28 CEST 2009

2009/9/17 paweł kamiński <kamiseq@REDACTED>:
> (I cant really use self() - is that correct??) by others so I CANT RECEIVE ANY
Why do you think so? You can use self() in init/1 and you can receive
messages. No problem here. But you have to use message primitives (!
and receive), not the gen_server's counterparts.

> so I though I can spawn another processes while in init/1 that
> will loop and ping another side if it is ready. but I am afraid that there
> might be a chance that the gen_server will not yet return from init and
> spawned worker will try to send some notification, so or I will miss it or
> there will be some error.

There is no problem with synchronizing two such processes. And you
don't have to spawn any process at all - you can do anything you want
in init/1. Either way this process will be stuck in init/1, so no
reason to spawn another process (unless there is something else
important in your situation).

If the initialization can take some extended time I'd use gen_fsm
instead, which will have two states (e.g. 'initializing' and 'ready').

> is this really a problem or Im just missing something here that is so
> obvious.
> All I really need is to init state of the gen_server, then start dynamically
> initializing the server so I cant hard code all conditions in init fun and I
> need to communicate with other processes.
> hope it is more or less clear
> take care
> pozdrawiam
> Paweł Kamiński
> kamiseq@REDACTED
> pkaminski.prv@REDACTED

Pozdrawiam serdecznie,
Gleb Peregud

More information about the erlang-questions mailing list