[erlang-questions] Is a supervisor necessary here/when should I use one?

code wiget codewiget95@REDACTED
Fri Jul 21 21:35:48 CEST 2017


Hello,

I have an Erlang server running on my system(emqtt), and I created a plugin for it. In this plugin, I have one function that I would like to run once on startup called startup() that passes the next function to the environment as a function reference and is used thousands of times a minute (ideally). My function simply searches a database for a key and returns a value.

The function that is run hundreds of times a minute does not wait around with a receive though. I am reading the textbook “learn you some Erlang for good,” and all of the “workers” described are constantly waiting on messages(receive) and performing actions.  This function is just a function though… like if you had a function 2+2, it is simple. 

So, when I enable the plugin and the supervisor starts, my startup() function is run properly, but exits and error text is displayed after completing properly because the worker is not, well, doing anything until it is started to be called.

Conceptually, I am new to this. Is there any place for a supervisor here? My goals are to run the startup script that just sets the function in the environment and to optimize my function speed. If there is no place for a supervisor, how would I run my Erlang startup program without having the console freak out at me?

Thank you for your help!


More information about the erlang-questions mailing list