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