(container: User)
| 24 | } |
| 25 | |
| 26 | public async load(container: User): Promise<void> { |
| 27 | const logger = this._logger.create("load"); |
| 28 | // only register events if there's an access token and it has an expiration |
| 29 | if (container.access_token && container.expires_in !== undefined) { |
| 30 | const duration = container.expires_in; |
| 31 | logger.debug("access token present, remaining duration:", duration); |
| 32 | |
| 33 | if (duration > 0) { |
| 34 | // only register expiring if we still have time |
| 35 | let expiring = duration - this._expiringNotificationTimeInSeconds; |
| 36 | if (expiring <= 0) { |
| 37 | expiring = 1; |
| 38 | } |
| 39 | |
| 40 | logger.debug("registering expiring timer, raising in", expiring, "seconds"); |
| 41 | this._expiringTimer.init(expiring); |
| 42 | } |
| 43 | else { |
| 44 | logger.debug("canceling existing expiring timer because we're past expiration."); |
| 45 | this._expiringTimer.cancel(); |
| 46 | } |
| 47 | |
| 48 | // if it's negative, it will still fire |
| 49 | const expired = duration + 1; |
| 50 | logger.debug("registering expired timer, raising in", expired, "seconds"); |
| 51 | this._expiredTimer.init(expired); |
| 52 | } |
| 53 | else { |
| 54 | this._expiringTimer.cancel(); |
| 55 | this._expiredTimer.cancel(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public async unload(): Promise<void> { |
| 60 | this._logger.debug("unload: canceling existing access token timers"); |
no test coverage detected