Constructor
# new Scheduler(checkInterval, checkSession, onSessionExpired)
Parameters:
Name | Type | Description |
---|---|---|
checkInterval |
number
|
The interval in milliseconds between periodic session checks. |
checkSession |
SessionCheckCallback
|
The callback function to perform a session check. |
onSessionExpired |
SessionExpiredCallback
|
The callback function to handle session timeout events. |
Classes
Methods
# calcTimeToNextCheck(lastCheck) → {number}
Calculates the time until the next session check should occur.
Parameters:
Name | Type | Description |
---|---|---|
lastCheck |
number
|
The timestamp (in milliseconds) of the last session check. |
The time in milliseconds until the next check should be performed.
number
# isRunning() → {boolean}
Checks if the scheduler is currently running.
True if the scheduler is running; otherwise, false.
boolean
# scheduleSessionExpiry(timeToExpiration) → {void}
Handles the session expiration when it is about to expire soon.
Stops any ongoing checks and schedules a timeout for the expiration.
Parameters:
Name | Type | Description |
---|---|---|
timeToExpiration |
number
|
The time in milliseconds until the session expires. |
void
# sessionExpiresSoon(expiration) → {boolean}
Checks if the session is about to expire.
Parameters:
Name | Type | Description |
---|---|---|
expiration |
number
|
Timestamp when the session will expire. |
True if the session is about to expire; otherwise, false.
boolean
# start(lastCheck, expiration) → {void}
Starts the session check process.
Determines when the next check should run based on the last known check time and session expiration.
If the session is expiring soon, schedules an expiration event instead of starting periodic checks.
Parameters:
Name | Type | Description |
---|---|---|
lastCheck |
number
|
The timestamp (in milliseconds) of the last session check. |
expiration |
number
|
The timestamp (in milliseconds) of when the session expires. |
void