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

jswny
I would like to better understand what the advantages/disadvantages of umbrella applications are compared to structuring your app as as s...
New
Rustixir
Hi everyone, im working on find best language/framework/system for high concurrency, high performance and stable performance after wor...
New
Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
fireproofsocks
I’ve been working on an Elixir project that has required a lot of scripting. I usually reach for Elixir because I like it more (and in th...
New
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
eteeselink
Hi all, In the last days, two things happened: A blog post titled “They might never tell you it’s broken” made the rounds. It’s about ...
New
jsonify
So, is Heroku the only free option for hosting Phoenix/Elixir at this point? I’m not ready to commit to paying monthly and was wondering ...
New
scouten
I’m looking for a host for the server part of a small (personal) side project that I’m working on. It’s currently written in Node.js and ...
New
Markusxmr
Since Drab has been developed for a while in the open, introducing the Liveview functionality in a way it happend appears to undermine th...
New

Other popular topics Top

chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43591 214
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52238 488
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement