| 15 | } |
| 16 | |
| 17 | class UserCacheEntry { |
| 18 | status: Status; |
| 19 | promise: Promise<Record<string, any>>; |
| 20 | expiry?: number; |
| 21 | |
| 22 | constructor(id: string, promise: Promise<Record<string, any>>) { |
| 23 | this.status = Status.WAITING; |
| 24 | this.promise = promise; |
| 25 | promise.then(_ => { |
| 26 | console.log('Fetched user ID ' + id); |
| 27 | this.status = Status.DONE; |
| 28 | this.expiry = (new Date().getTime()) + (60 * 1000); |
| 29 | }).catch(reason => { |
| 30 | console.error('Failed to fetch user', reason); |
| 31 | this.status = Status.FAILED; |
| 32 | }); |
| 33 | } |
| 34 | |
| 35 | get invalid() { |
| 36 | if (this.status === Status.FAILED) |
| 37 | return true; |
| 38 | if (this.expiry !== undefined && (new Date().getTime()) > this.expiry) |
| 39 | return true; |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export class UserCache { |
| 45 | oauth: OAuth; |
nothing calls this directly
no outgoing calls
no test coverage detected