Skip to content

Commit

Permalink
Merge pull request #631 from Th3-M4jor/allow-let-it-crash-consumer-mo…
Browse files Browse the repository at this point in the history
…dule

Proposal: Allow consumers to follow "let it crash" methodology
  • Loading branch information
jb3 committed Sep 11, 2024
2 parents 8e6e82e + 0622cf7 commit 360cdc5
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 360cdc5

Please sign in to comment.