TokenRefreshTimer class
Periodically calls TokenKeeper.getValidToken to keep the stored token warm before it expires.
Primarily useful in background services, daemon processes, or any context where HTTP requests may not fire frequently enough to trigger the on-demand refresh in TokenKeeper.getValidToken.
For on-demand apps (regular Flutter UI), the proactive refresh window on TokenKeeper is usually sufficient and you don't need this class.
Usage
final timer = TokenRefreshTimer(
keeper: keeper,
checkInterval: const Duration(minutes: 5),
);
timer.start();
// When you're done (e.g. the user logs out):
timer.dispose();
Configure the keeper with a proactiveWindow larger than checkInterval
so the periodic tick has a chance to refresh before actual expiry:
TokenKeeper(proactiveWindow: const Duration(minutes: 10), ...);
TokenRefreshTimer(keeper: keeper, checkInterval: const Duration(minutes: 5));
Constructors
- TokenRefreshTimer({required TokenKeeper keeper, Duration checkInterval = const Duration(minutes: 1), Clock clock = const Clock(), TokenKeeperLogger logger = noopLogger})
- Creates a timer. Call start to begin periodic checks.
Properties
- checkInterval → Duration
-
How often to call TokenKeeper.getValidToken. Defaults to 1 minute.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isRunning → bool
-
Whether the timer is currently running.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
dispose(
) → void - Stops the timer permanently. The TokenRefreshTimer cannot be restarted after this.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
start(
) → void - Starts periodic token checks. A no-op if already running or disposed.
-
stop(
) → void - Stops the timer without disposing the keeper. Safe to call multiple times. Call start to resume.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited