( promise: Promise<T>, timeoutMs: number, timeoutMessage: string, )
| 39 | } |
| 40 | |
| 41 | function withTimeout<T>( |
| 42 | promise: Promise<T>, |
| 43 | timeoutMs: number, |
| 44 | timeoutMessage: string, |
| 45 | ): Promise<T> { |
| 46 | if (timeoutMs <= 0) { |
| 47 | return promise |
| 48 | } |
| 49 | |
| 50 | return new Promise<T>((resolve, reject) => { |
| 51 | const timer = setTimeout(() => { |
| 52 | reject(new InvalidPersistedCollectionConfigError(timeoutMessage)) |
| 53 | }, timeoutMs) |
| 54 | |
| 55 | promise.then( |
| 56 | (value) => { |
| 57 | clearTimeout(timer) |
| 58 | resolve(value) |
| 59 | }, |
| 60 | (error: unknown) => { |
| 61 | clearTimeout(timer) |
| 62 | reject(error) |
| 63 | }, |
| 64 | ) |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | function assertValidResponse( |
| 69 | response: ElectronPersistenceResponseEnvelope, |
no outgoing calls
no test coverage detected