Description
I believe one of the most common use cases for the time related functions millis()
and micros()
is to detect timeouts. In a nutshell you take the current time and loop until you succeed on something or bail out when you hit the timeout. An example of such a loop can be seen here:
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Stream.cpp#L31-L40
Many people use the same pattern in their libraries:
https://github.com/arduino-libraries/ArduinoHttpClient/blob/master/src/HttpClient.cpp#L414-L420
The problem is that the return value of millis()
does not advance between calls if it’s not manually set. When calling a function that expects the clock to go forward it will never return because it is impossible to set a new value for the millis while the other function is being executed.
An easy fix would to increment the return values of millis()
and micros()
by one on every call. If needed this behaviour could be configurable.
Any ideas?