Your Elixir bucket for debugging

While debugging and experimenting with apis in javascript, I usually set a variable on window and then play with it in the console.

1
2
3
4
5
6

// ....

let channel = socket.channel( //...

window.channel = channel;

Once the above code is set, I can just jump into the console and start pushing messages to the channel and discover how it all works by poking it around.

This led me to think about how this can be done in Elixir. And, in one of my recent projects, I was spawning a few processes and wanted to get their pids to play around by sending messages to them. And I just thought why not use ets as global bucket to shove stuff into. Here is my solution:

Just create an ets table in your .iex.exs

1
2
3
# .iex.exs
# A tmp bucket which you can push stuff into and analyze from iex
:ets.new(:tmp, [:named_table, :public])

And, wherever you want, just push things into this table:

1
2
3
4
# in my app
def websocket_info(_msg, _conn, state) do
:ets.insert(:tmp, {self(), :ok})
# ...

Once you have that, you can start poking and prodding your processes/variables

1
2
# iex>
:ets.tab2list(:tmp)

Hope this helps you while debugging your Elixir apps :D


I am currently working on Zammu which makes Automatic Deployment of static websites to Github Pages very easy. I would love to get your feedback on it, Use the invitation code KHAJA