Skip to content

Commit

Permalink
Allow consumers to follow "let it crash" methodology
Browse files Browse the repository at this point in the history
  • Loading branch information
Th3-M4jor committed Sep 9, 2024
1 parent 8e6e82e commit 0622cf7
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions lib/nostrum/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ defmodule Nostrum.Consumer do
```elixir
def handle_info({:event, event}, state) do
Task.start_link(fn ->
__MODULE__.handle_event(event)
Task.start(fn ->
try do
__MODULE__.handle_event(event)
rescue
e ->
Logger.error("Error in event handler: \#{Exception.format_error(e, __STACKTRACE__)}")
end
end)
{:noreply, state}
Expand Down Expand Up @@ -408,6 +413,8 @@ defmodule Nostrum.Consumer do
quote location: :keep do
use GenServer

require Logger

@behaviour Nostrum.Consumer

@before_compile Nostrum.Consumer
Expand Down Expand Up @@ -436,8 +443,15 @@ defmodule Nostrum.Consumer do
@impl GenServer
def handle_info({:event, event}, state) do
{:ok, _pid} =
Task.start_link(fn ->
__MODULE__.handle_event(event)
Task.start(fn ->
try do
__MODULE__.handle_event(event)
rescue
e ->
Logger.error(
"Error in event handler: #{Exception.format_error(e, __STACKTRACE__)}"
)
end
end)

{:noreply, state}
Expand Down

0 comments on commit 0622cf7

Please sign in to comment.