Skip to content

Timers (or how to do setInterval and clearInterval in Elixir / Erlang?) #225

Open
@nelsonic

Description

@nelsonic

I'm making a few million API requests to get some data dwyl/who#17
and need to control the request frequency to avoid hitting rate limits ... ⏳ (5k/hour -> 120k/day -> 3.65m/month )
In JS-land I would just use setInterval to define the timeframe for executing the API requests
and clearInterval once they were complete.
Not had to do this in Elixir before, so doing a bit of googling ... 🔍

Reading:
https://stackoverflow.com/questions/43892784/what-are-the-equivalent-of-settimeout-and-setinterval-in-elixir

image

The recommended Erlang function is: timer.apply_interval/4

:timer.apply_interval(1000, IO, :puts, ["weee"])

https://www.erlang.org/doc/apps/stdlib/timer.html

Need to write myself a mini example ...

Side note: notice how this question on StackOverflow that has clearly been useful to other people got 4 downvotes:
stackoverflow-downvotes-on-questions
yes, it doesn't conform to the narrow SO question guidelines, but it's still a useful question/answer!
SO is just not a very welcoming (to beginners) environment. 😞
This in a nutshell is why ChatGPT which just repackages the web is so popular: it doesn't "judge" your ("stupid") questions!

Metadata

Metadata

Assignees

Labels

T25mTime Estimate 25 MinutesdiscussShare your constructive thoughts on how to make progress with this issueelixirPull requests that update Elixir codeenhancementNew feature or enhancement of existing functionalityhelp wantedIf you can help make progress with this issue, please comment!priority-2Second highest priority, should be worked on as soon as the Priority-1 issues are finishedquestionA question needs to be answered before progress can be made on this issueresearchResearch required; be specifictechnicalA technical issue that requires understanding of the code, infrastructure or dependencies

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions