AstonJ

AstonJ

Code you love - share yours!

Thought this would be a nice way to start the year - have you seen or written an Elixir function or piece of code that you are particularly fond of? Perhaps you admired its simplicity (or complexity!) or maybe your surprised yourself or surpassed your own expectations of what is possible?

Whatever the reason, please share! :blush:

Most Liked

Rob1

Rob1

Thanks for this question Aston. I hope my response adds value to this forum :), I didn’t post this anywhere yet:

I finished learning the basic Elixir syntax and put up this simple example of a GenServer with Supervisor project.

I was able to run a million tasks in 4.2 seconds seconds on my PC which is very good for a task queue like this, it means dispatching approximately 238,095 tasks per second which is very good.

I do realize that the latest HexDocs “antipatterns” document specifically calls out creating unnecessary GenServers:

An example of this anti-pattern, as shown below, is a module that implements arithmetic operations (like add and subtract ) by means of a GenServer process

And then pretty much shows something very similar to what I made, so I realize that it is not really an example of where I would use a GenServer in production.

But I feel proud of completing this task, since GenServers and supervisors are one of the more advanced concepts in Elixir, and this is, after all, a complete application that uses them.

hlx

hlx

Very good! If you are looking for next steps:

  • Look at replacing IO.puts/1 with Logger.debug/2
  • Write some tests that interact with the GenServer
  • See if you can start the genserver with a DynamicSupervisor

Where Next?

Popular in Discussions Top

tomekowal
Hey guys! I want to create a toy project that shows a chart of temperature over time and updates every 5 seconds. I feel LiveView is per...
New
Fl4m3Ph03n1x
Background A few days ago I was listening to The future of Elixir from Elixir Talks, with Dave Thomas (@pragdave ) and Brian Mitchell. I...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
owaisqayum
I have a sample string sentence = "Hello, world ... 123 *** ^%&*())^% %%:>" From this string, I want to only keep the integers, ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
crispinb
On reading dhh’s latest The One Person Framework it strikes me that Phoenix with LiveView is already pretty much this. However, never hav...
New
arcanemachine
https://nitter.net/josevalim/status/1744395345872683471 https://twitter.com/josevalim/status/1744395345872683471
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement