@@ -228,10 +228,11 @@ class timeoutTemplate
228
228
timeType remaining () const
229
229
{
230
230
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));
235
236
}
236
237
237
238
static constexpr timeType timeMax ()
@@ -242,11 +243,11 @@ class timeoutTemplate
242
243
private:
243
244
244
245
IRAM_ATTR // fast
245
- bool checkExpired () const
246
+ bool checkExpired (const timeType internalUnit ) const
246
247
{
247
248
// canWait() is not checked here
248
249
// returns "can expire" and "time expired"
249
- return (!_neverExpires) && ((_current - _start) >= _timeout);
250
+ return (!_neverExpires) && ((internalUnit - _start) >= _timeout);
250
251
}
251
252
252
253
protected:
@@ -257,27 +258,25 @@ class timeoutTemplate
257
258
if (!canWait ())
258
259
return true ;
259
260
260
- _current = TimePolicyT::time ();
261
- if (checkExpired ())
261
+ timeType current = TimePolicyT::time ();
262
+ if (checkExpired (current ))
262
263
{
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)
264
265
_start += n * _timeout;
265
266
return true ;
266
267
}
267
268
return false ;
268
269
}
269
270
270
271
IRAM_ATTR // fast
271
- bool expiredOneShot ()
272
+ bool expiredOneShot () const
272
273
{
273
- _current = TimePolicyT::time ();
274
274
// returns "always expired" or "has expired"
275
- return !canWait () || checkExpired ();
275
+ return !canWait () || checkExpired (TimePolicyT::time () );
276
276
}
277
277
278
278
timeType _timeout;
279
279
timeType _start;
280
- timeType _current;
281
280
bool _neverExpires;
282
281
};
283
282
0 commit comments