<div dir="ltr">I know about hanle_continue but my question is not about long init() function. <div>To make it simpler it is about long-running functions inside of handle_continue. </div><div>It may be possible to spawn those functions in different processes but it is not </div><div>desirable because of requirements.<br><br>mod_func is quite general (general like a library) and should not know about </div><div>anything specific outside of it. Passing to mod_func something like 'reply_to' reference </div><div>could be possible but it is fragile - response side could be not ready at the</div><div> moment of replying and this *single* notification would just vanish. </div><div>So notification from mod_func to mod_api is the same problem but from the other side.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">вс, 16 мая 2021 г. в 02:50, Leonard B <<a href="mailto:leonard.boyce@lucidlayer.com">leonard.boyce@lucidlayer.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Why not notify mod_api from mod_func once it's initialized. If you wanted mod_func initialization to be non-blocking you could use handle_continue.<div dir="auto"><br></div><div dir="auto">Kind regards,</div><div dir="auto">Leonard</div><br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 15, 2021, 14:55 Stanislav Ledenev <<a href="mailto:s.ledenev@gmail.com" target="_blank">s.ledenev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi!<br>Need advice from an experienced community about synchronizing long initializing gen_server with other parts of application.<br> <br>Let's say we have 4 gen_servers:<br>* mod_api - accept requests;<br>* mod_func - real job;<br>* mod_x, mod_y - users of mod_func.<br><br>mod_api accepts requests and transforms them to calls to mod_x, mod_y.<br>mod_func is crucial for the application but it needs a time consuming procedure <div>of initialization. IRL it is some cryptography related stuff. </div><div>While mod_func is in the initialization state, mod_api must return 'not_ready' for all requests.<br>While mod_func initializing it is not available for any requests.<br><br>I was thinking about options of notification mechanism implementation and see two of them:<br>1. Some kind of polling from mod_api to mod_func with gen_server:call with timeout: mod_api after initialization begin send_after loop with timeout call to mod_func;<br>2. gen_event based solution. Run up gen_event and wait for notification about readiness of mod_func.<br><br>Am I missing something? Are there any better solutions for such a task?<br></div></div>
</blockquote></div></div></div>
</blockquote></div>