Process is the concurrency primitive in ErlangVM To have State, we need server process which basically a recursive function call to keep it alive.
Simple wrapper around state. Keep state.
{:ok, agent} = Agent.start_link fn -> [] end
Agent.update(agent, fn list -> ["eggs" | list] end)
:ok
Agent.get(agent, fn list -> list end)
["eggs"]
Agent.stop(agent)
:ok
async unit of computations. Tasks spawned with async can be awaited on by its caller above. (implemented y spawing a process that send a mesage to the caller once the given computation is done)
await
(The Task process send a message back with the result)
it use Process.monitor
to get notified if the task process crash
No GenServer is used for task
Generic Server
A specification and computational flow for Elixir. for us to define a pipeline of work to be carried out by independent steps (or stages) in a seprate process.
- producer-consumer flow
- exchanging events with bak-pressure between Elixir processes.
- abstract away dispatching data and back-pressure. so we focus on producing, manipulated and cponsuming events a stage can be producer, consumer or both.
- :producer source. producer wait for demand from consumers and respond with the requested events.
- :producer_consumer both a source and a sink. it respond to demand from other consumers as well as request events from producers
- :consumer a sink. request and receives data from producers.
Use Cases:
-
Data Transformation Pipieline. e.g produce events from db, Kafka and then we process, sort, catalog or store metrics
-
Work Queue
-
Event Processing