CommunityNews

CommunityNews

Learning Elixir's `GenServer` with a real-world example

I started learning Elixir a few months ago, mostly through hacking on Papercups. I’m ashamed to say most of my Elixir education has been through trial and error, figuring things out as I go along. So this past week I decided to take some time off from Papercups to go a bit deeper into the language.

In particular, I was itching to learn more about handling concurrency in Elixir. This, of course, led me to GenServers.

Anyone who’s moderately familiar with Elixir has probably at least heard of GenServer. (If you haven’t, that’s ok too!) Strictly speaking, it’s one of those things you can get away with avoiding for a while, and still be reasonably productive while using something like the Phoenix framework.

But it’s an incredible useful feature of the language that you can add to your toolbox! There are so many nice things you can do with it. For example, with GenServers, you can:

  • create a simple cache, buffer, or rate limiter
  • set up recurring tasks to run every few hours (e.g. check out Jose’s answer to “How can I schedule code to run every few hours in Elixir?” on Stack Overflow)
  • handle async processes much more easily, with built-in functionality for tracing, error reporting, and retry logic

…all without any external dependencies!

This thread was posted by one of our members via one of our automated news source trackers.

Where Next?

Popular Backend topics Top

Scorpil
I dabbled in Phoenix for a while now, but never really got my hands dirty with it right up until now. Apart from the whole framework bein...
New
First poster: bot
Part 1: Introduction to Postgrest. In Codd, we trust In the field of Computer Science and Engineering, few things come close to the dura...
New
First poster: bot
One of my favourite programming languages in the last few years has been Crystal. While the language has not yet reached its 1.0 version,...
New
prajaut
Being a part of the tech industry, it would be good to share thoughts on specific technologies. Having surrounded by skilled and experie...
/go
New
First poster: malloryerik
Everyone outside of tech has heard of JavaScript, Java, Python, Ruby and even .Net, but few if any have heard of F#. However, F# may be o...
New
First poster: bot
Just a small test with lists in cython. Considering echosystem, multithreading and ease of use, Julia is a clear winner here.
New
pablocostass
Todos coñecemos os focos de Erlang/Elixir máis renomeados do mundo, como a Suecia, o Brasil, a California ou Londres. Mais a comunidade, ...
New
First poster: bot
I wrote Python for the last 10 years, and I always tend to write code in a “functional” way - map, filter, lambda and so on, it makes me ...
New
New
GoulvenClech
Hi everyone :wave: I’m excited to share an article detailing how we have reorganized our Elixir/Phoenix project’s directory structure. W...
New

Other popular topics Top

New
Rainer
My first contact with Erlang was about 2 years ago when I used RabbitMQ, which is written in Erlang, for my job. This made me curious and...
New
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25883 760
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New