Skip to content

Commit

Permalink
Avoid deprecated Elixir syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Feb 11, 2025
1 parent 93174d0 commit df77232
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/db_connection/backoff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ defmodule DBConnection.Backoff do
end

def backoff(%Backoff{type: :exp, min: min, state: nil} = s) do
{min, %Backoff{s | state: min}}
{min, %{s | state: min}}
end

def backoff(%Backoff{type: :exp, max: max, state: prev} = s) do
require Bitwise
next = min(Bitwise.<<<(prev, 1), max)
{next, %Backoff{s | state: next}}
{next, %{s | state: next}}
end

def backoff(%Backoff{type: :rand_exp, max: max, state: state} = s) do
{prev, lower} = state
next_min = min(prev, lower)
next_max = min(prev * 3, max)
next = rand(next_min, next_max)
{next, %Backoff{s | state: {next, lower}}}
{next, %{s | state: {next, lower}}}
end

@spec reset(t) :: t
def reset(backoff)

def reset(%Backoff{type: :rand} = s), do: s
def reset(%Backoff{type: :exp} = s), do: %Backoff{s | state: nil}
def reset(%Backoff{type: :exp} = s), do: %{s | state: nil}

def reset(%Backoff{type: :rand_exp, min: min, state: {_, lower}} = s) do
%Backoff{s | state: {min, lower}}
%{s | state: {min, lower}}
end

## Internal
Expand Down

0 comments on commit df77232

Please sign in to comment.