Handle arbitrarily high integer values in Process.sleep/1 #13649
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A while ago OTP timer module was changed to support sleeping with arbitrarily high integer timeout values. Given that
Process.sleep/1
is almost the same as:timer.sleep/1
it seems that Elixir could support this too.There are a number of ways to implement it, each with it's own tradeoffs regarding backward compatibility when supplying wrong types.
In this PR I just translated Erlang's implementation to Elixir. This allows it to keep
FunctionClauseError
on bad input, but error text now mentionstimeout > 4_294_967_295
guard which can be confusing to the end user.There is also an option of just delegating sleep to
:timer
, though in this case we would be gettingErlangError
instead ofFunctionClauseError
:The third option is to keep the guards as is and "delegate" to
:timer.sleep
by hand in the function body.This change allows to keep the error message exactly as it was, but introduces a function call with an additional (redundant) argument check.
I'm not sure what is Elixir's stability commitment in regards to exception values, so I'm ready to supply the code for any one of these cases 😃