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