Skip to content

Commit

Permalink
Add comment clarifying the purpose of Scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
ljwagerfield committed Jul 17, 2024
1 parent 85fbd3f commit 8fbfea7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/private/Scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { ConsoleUtils } from "./ConsoleUtils";

/**
* -------------------------
* Q: Why not use 'setTimeout'?
* -------------------------
* A: setTimeout can be paused (e.g., during hibernation), risking JWT expiration before it triggers.
* We therefore use a scheduler to check wall-clock time every second and execute the callback at the scheduled time.
* -------------------------
*/
export class Scheduler {
private callbacks: { [handle: number]: { callback: () => void; epoch: number } } = {};
private nextId: number = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/public/browser/AuthManagerBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ class AuthManagerImpl implements AuthManagerInterface {
// 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.
ConsoleUtils.warn(`Unable to refresh JWT access token: ${e as string}`);
} finally {
// 'setTimeout' can be paused (e.g., during hibernation), risking JWT expiration before it triggers. We use a
// scheduler to check wall-clock time every second and execute the callback at the scheduled time (below).
session.accessTokenRefreshHandle = this.scheduler.schedule(expires, () => {
this.refreshAccessToken(session).then(
() => {},
Expand Down

0 comments on commit 8fbfea7

Please sign in to comment.