Adworse Codes Here

Rubyist Elixir Journey

Menu
  • About me
  • Privacy Policy
Menu

The Curious Case of String.slice/3

Posted on July 16, 2022August 4, 2022 by Dima Ermilov

Slicing a string isn’t tricky, right? Or is it? Elixir works wonderfully with strings. Some edge parts of it could be a little bit confusing though. This one led me to a rabbit hole deep down to IO devices and improper lists.

Say, we have some text data like a company name, some web page to show it, and some database to store it. Say, we’re not the one who designed both the web page and the DB, so they both have 80 characters limit, and there’s nothing we can do about it.…

Read more
Category: We Need To Go Deeper

Singleton GenServer: Short track to the orphanage

Posted on July 16, 2022July 18, 2022 by Dima Ermilov

While writing a GenServer as a singleton on a multi-node system, it’s easy to come up with something like this:

def start_link(_number, _opts \\ []) do
  case GenServer.start_link(__MODULE__, :ok, name: {:global, __MODULE__}) do
    {:ok, pid} ->
      {:ok, pid}

    {:error, {:already_started, pid}} ->
      {:ok, pid}
  end
end

It works perfectly until it doesn’t: when our singleton process goes down, the only supervision tree aware of this would be the one that started it. Every other node won’t get any message, so while the process is restarting, the caller will fail with Process is not alive.…

Read more
Category: Learned the Hard Way

Recent Posts

  • The Curious Case of String.slice/3
  • Singleton GenServer: Short track to the orphanage

Recent Comments

No comments to show.

Archives

  • July 2022

Categories

  • Learned the Hard Way
  • We Need To Go Deeper
©2023 Adworse Codes Here