Skip to content

Allow float keywords in to_timeout/1.#15400

Closed
christhekeele wants to merge 3 commits into
elixir-lang:mainfrom
christhekeele:float-timeouts
Closed

Allow float keywords in to_timeout/1.#15400
christhekeele wants to merge 3 commits into
elixir-lang:mainfrom
christhekeele:float-timeouts

Conversation

@christhekeele
Copy link
Copy Markdown
Contributor

@christhekeele christhekeele commented May 18, 2026

Per core discussion, I ran into another situation with a dynamically-calculated rate limit from an API response (in fractional minutes), and thought I would proffer an implementation.

While floats are not allowed in Durations, it makes sense to me that since the purpose of to_timeout/1 is not to construct a Duration, a general-purpose Kernel function should be made more flexible. Duration and simple numeric arguments still require integers, to encourage thinking of timeouts on millisecond timescales.

I understand the mailing list discussion did not end with a [👍 PRs welcome], so feel free to close if the argument for this form is not sufficiently persuasive.

@josevalim
Copy link
Copy Markdown
Member

Thank you but I am not comfortable with supporting floats, given the imprecision from operations and the fact timeouts in Erlang are only integer too. I understand the application specific concerns but then I suggest those be tackled by the application. :)

PS: if we were to merge it, then I would suggest rounding up, as timeout guarantees “at least”. But as per above, I wouldn’t go ahead with this feature.

@christhekeele
Copy link
Copy Markdown
Contributor Author

christhekeele commented May 18, 2026

Your reservations make sense! This PR does in fact round to always get integers, and always rounds up, to eat the imprecisions, FWIW. See:

Fractional milliseconds are rounded upwards with ceil/1 to ensure the timeout exceeds the requested value.

@josevalim
Copy link
Copy Markdown
Member

We won't go ahead with this, per above. :)

This PR does in fact round to always get integers, and always rounds up, to eat the imprecisions

Ah, perfect. I got confused with the mailing message then!

@josevalim josevalim closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants