Skip to content

Commit 8fbfea7

Browse files
committed
Add comment clarifying the purpose of Scheduler
1 parent 85fbd3f commit 8fbfea7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/private/Scheduler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import { ConsoleUtils } from "./ConsoleUtils";
22

3+
/**
4+
* -------------------------
5+
* Q: Why not use 'setTimeout'?
6+
* -------------------------
7+
* A: setTimeout can be paused (e.g., during hibernation), risking JWT expiration before it triggers.
8+
* We therefore use a scheduler to check wall-clock time every second and execute the callback at the scheduled time.
9+
* -------------------------
10+
*/
311
export class Scheduler {
412
private callbacks: { [handle: number]: { callback: () => void; epoch: number } } = {};
513
private nextId: number = 0;

src/public/browser/AuthManagerBrowser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class AuthManagerImpl implements AuthManagerInterface {
148148
// Use 'warn' instead of 'error' since this happens frequently, i.e. user goes through a tunnel, and some customers report these errors to systems like Sentry, so we don't want to spam.
149149
ConsoleUtils.warn(`Unable to refresh JWT access token: ${e as string}`);
150150
} finally {
151+
// 'setTimeout' can be paused (e.g., during hibernation), risking JWT expiration before it triggers. We use a
152+
// scheduler to check wall-clock time every second and execute the callback at the scheduled time (below).
151153
session.accessTokenRefreshHandle = this.scheduler.schedule(expires, () => {
152154
this.refreshAccessToken(session).then(
153155
() => {},

0 commit comments

Comments
 (0)