What is the use of on_load() in Erlang programming?

Total Post:107

Points:535

erlang 
 1073  View(s)
Ratings:
Rate this:
  1. What is the use of on_load() in Erlang programming?

    The on_load directive name is a function which will run automatically whenever a module is loaded. If we use on_load() function then it is not necessary to export the function because when on_load() function will call it will create a newly spawned process (means: it will generate a new process) and the function must return ok if the module is to remain loaded and become callable.It will generate an exception also causes the module to be unloaded.
    If the return value is not an atom then a warning error report will be sent to the error logger. and until the on_load() function returns ok the system will not terminated.
    Syntax:
    -on_load(Function_Name/0).

Answer