@@ -228,10 +228,11 @@ class timeoutTemplate
228228 timeType remaining () const
229229 {
230230 if (_neverExpires)
231- return timeMax ();
232- if (expired ())
233- return TimePolicyT::toUserUnit (0 );
234- return TimePolicyT::toUserUnit (_timeout - (_current - _start));
231+ return timeMax ();
232+ timeType current = TimePolicyT::time ();
233+ if (checkExpired (current))
234+ return TimePolicyT::toUserUnit (0 );
235+ return TimePolicyT::toUserUnit (_timeout - (current - _start));
235236 }
236237
237238 static constexpr timeType timeMax ()
@@ -242,11 +243,11 @@ class timeoutTemplate
242243private:
243244
244245 IRAM_ATTR // fast
245- bool checkExpired () const
246+ bool checkExpired (const timeType internalUnit ) const
246247 {
247248 // canWait() is not checked here
248249 // returns "can expire" and "time expired"
249- return (!_neverExpires) && ((_current - _start) >= _timeout);
250+ return (!_neverExpires) && ((internalUnit - _start) >= _timeout);
250251 }
251252
252253protected:
@@ -257,27 +258,25 @@ class timeoutTemplate
257258 if (!canWait ())
258259 return true ;
259260
260- _current = TimePolicyT::time ();
261- if (checkExpired ())
261+ timeType current = TimePolicyT::time ();
262+ if (checkExpired (current ))
262263 {
263- unsigned long n = (_current - _start) / _timeout; // how many _timeouts periods have elapsed, will usually be 1 (_current - _start >= _timeout)
264+ unsigned long n = (current - _start) / _timeout; // how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout)
264265 _start += n * _timeout;
265266 return true ;
266267 }
267268 return false ;
268269 }
269270
270271 IRAM_ATTR // fast
271- bool expiredOneShot ()
272+ bool expiredOneShot () const
272273 {
273- _current = TimePolicyT::time ();
274274 // returns "always expired" or "has expired"
275- return !canWait () || checkExpired ();
275+ return !canWait () || checkExpired (TimePolicyT::time () );
276276 }
277277
278278 timeType _timeout;
279279 timeType _start;
280- timeType _current;
281280 bool _neverExpires;
282281};
283282
0 commit comments