If you are interested in Elixir, it will be interesting for you to get to read more about this programming language in our blog. Today we are going to show you how you can use Elixir Component library for writing code as servers.
The Component Library makes it easy to create simple servers. It is an attempt to make it so easy to write trivial standalone servers that people will just naturally split their applications up that way.
A component is a simple module, containing what looks like function definitions. This library generates from it an API module, a GenServer module, and an implementation module.
There is a number of component types:
- global: a singleton process
- dynamic: on-demand processes
- pooled: a pool of processes that typically represent limited resources
- hungry: a pool of processes that process a collection in parallel
A global component must be created before use. Once created, it may be accessed by simply calling the functions it contains. There is no need to identify a particular worker, as there is only one per component. A global component may be destroyed, in which case it must be recreated before being used again.
Dynamic and pooled components must be initialized. This process does not necessarily create any worker processes; it simply prepares the component for use.
With dynamic components you gain access to a worker by telling the component to create it. This returns an identifier for that worker process, which you must pass to subsequent calls to functions in the component. You should eventually destroy workers that you create.
Pooled components are automatically created when needed, so there’s no need to call their
Here you can find more details on the subject.
By the way, do you know that Elixir v1.8 released?