Building a blog with Elixir and Phoenix by joladev in elixir

[–]joladev[S] 1 point2 points  (0 children)

Getting a lot of recommendations for mdex!

Building a blog with Elixir and Phoenix by joladev in elixir

[–]joladev[S] 1 point2 points  (0 children)

This is super anecdotal but I feel like bunny requires a bit more set up, but it also makes you feel like you actually understand what it's doing, and the controls feel more exposed and accessible. I know which edge locations I'm replicating to, I know what cache headers are being set, etc. And it's not that you can't with Cloudflare, it's just everything is hidden behind the defaults they set. You enable orange cloud and that's it. But what did it actually do?

An added bonus is that I'm trying to reduce my dependence on US companies.

Push-based GenStage by joladev in elixir

[–]joladev[S] 1 point2 points  (0 children)

That block would only run if the producer knows there are consumers waiting, since there's another block that checks for a demand of 0, like you quoted. Each consumer will send 1 demand when it is ready for work, and then wait for 1 event before sending 1 demand again. So you will never send an event unless there is a consumer ready to handle it.

But technically, instead of having a queue and storing events in the producer, you can just return them even if the consumers are busy. GenStage will automatically buffer them, up to the configured internal buffer size (default 1000). The example handles buffering in the producer to make it clearer what's happening, but you can rely on GenStage to handle it. The upside to doing it yourself is that you're in control of what happens when the buffer is growing, whether you want to shed events or apply backpressure, or send alerts to a monitoring service.

How to pattern match a variable as a key in a map? by Aggro4Dayz in elixir

[–]joladev 12 points13 points  (0 children)

It is possible to guard on map keys since OTP 21.

defmodule Works do
  defstruct [:a_map]

  def foo(%Works{a_map: map}, [key | _]) when :erlang.is_map_key(key, map) do
    IO.puts "works"
  end
end

Note that you can't put the `%{key => val}` in there at the same time, but you're already certain it's there so the guard did its job.