Nafets94
Agent "Let it crash"
I have the following simple Agent
defmodule ListAdd do
use Agent
def addToList(agent, value) do
Agent.update(agent, fn list -> [value | list] end)
end
end
How can I crash it so it gets restarted by the supervisor? I’ve been searching around and looks like you can simulate this using it’s stop function [stop(agent, reason \\ :normal, timeout \\ :infinity)](https://hexdocs.pm/elixir/Agent.html#stop/3) found in the documentation?
Most Liked
cmkarlsson
You can use Process.exit/2 to kill a process.
Process.exit(agent, :somereason)
Process.exit(agent, :kill) # kills process even if trapping exits
The following is from the built-in help.
def exit(pid, reason)
Sends an exit signal with the given reason to the pid.
The following behaviour applies if reason is any term except :normal or :kill:
1. If pid is not trapping exits, pid will exit with the given reason.
2. If pid is trapping exits, the exit signal is transformed into a
message {:EXIT, from, reason} and delivered to the message queue of pid.
If reason is the atom :normal, pid will not exit (unless pid is the calling
process, in which case it will exit with the reason :normal). If it is trapping
exits, the exit signal is transformed into a message {:EXIT, from, :normal} and
delivered to its message queue.
If reason is the atom :kill, that is if exit(pid, :kill) is called, an
untrappable exit signal is sent to pid which will unconditionally exit with
reason :killed.
Inlined by the compiler.
## Examples
Process.exit(pid, :kill)
2
lpil
Creator of Gleam
I would say that “let it crash” is a statement about how unexpected errors should be handled, so a more realistic way to simulate a crash would be to call the update with a function with a bug that causes it to crash . For example you supply give a function that pattern matches on the incorrect data structure.
Why do you want your agent to crash? ![]()
1
Popular in Questions
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Other popular topics
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this
"1000"
What is the ...
New
Hi,
I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
Using vs code and installed ElixirLS: support and debugger.
And I got an error popped up on start up says
Failed to run ‘elixir’ comma...
New
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
Hi all,
I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I'm trying to use Postg...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New







