@@ -227,10 +227,11 @@ class timeoutTemplate
227
227
timeType remaining () const
228
228
{
229
229
if (_neverExpires)
230
- return timeMax ();
231
- if (expired ())
232
- return TimePolicyT::toUserUnit (0 );
233
- return TimePolicyT::toUserUnit (_timeout - (_current - _start));
230
+ return timeMax ();
231
+ timeType current = TimePolicyT::time ();
232
+ if (checkExpired (current))
233
+ return TimePolicyT::toUserUnit (0 );
234
+ return TimePolicyT::toUserUnit (_timeout - (current - _start));
234
235
}
235
236
236
237
static constexpr timeType timeMax ()
@@ -241,11 +242,11 @@ class timeoutTemplate
241
242
private:
242
243
243
244
IRAM_ATTR // fast
244
- bool checkExpired () const
245
+ bool checkExpired (const timeType internalUnit ) const
245
246
{
246
247
// canWait() is not checked here
247
248
// returns "can expire" and "time expired"
248
- return (!_neverExpires) && ((_current - _start) >= _timeout);
249
+ return (!_neverExpires) && ((internalUnit - _start) >= _timeout);
249
250
}
250
251
251
252
protected:
@@ -256,27 +257,25 @@ class timeoutTemplate
256
257
if (!canWait ())
257
258
return true ;
258
259
259
- _current = TimePolicyT::time ();
260
- if (checkExpired ())
260
+ timeType current = TimePolicyT::time ();
261
+ if (checkExpired (current ))
261
262
{
262
- unsigned long n = (_current - _start) / _timeout; // how many _timeouts periods have elapsed, will usually be 1 (_current - _start >= _timeout)
263
+ unsigned long n = (current - _start) / _timeout; // how many _timeouts periods have elapsed, will usually be 1 (current - _start >= _timeout)
263
264
_start += n * _timeout;
264
265
return true ;
265
266
}
266
267
return false ;
267
268
}
268
269
269
270
IRAM_ATTR // fast
270
- bool expiredOneShot ()
271
+ bool expiredOneShot () const
271
272
{
272
- _current = TimePolicyT::time ();
273
273
// returns "always expired" or "has expired"
274
- return !canWait () || checkExpired ();
274
+ return !canWait () || checkExpired (TimePolicyT::time () );
275
275
}
276
276
277
277
timeType _timeout;
278
278
timeType _start;
279
- timeType _current;
280
279
bool _neverExpires;
281
280
};
282
281
0 commit comments