* Chain the provided promise after all previous promises have successfully completed. * If the previously chained promises have failed, then this call will fail.
(promise: () => Promise<T>)
| 159 | * If the previously chained promises have failed, then this call will fail. |
| 160 | */ |
| 161 | public async chain<T>(promise: () => Promise<T>): Promise<T> { |
| 162 | const deferred = createDeferred<T>(); |
| 163 | const previousPromise = this.currentPromise; |
| 164 | this.currentPromise = this.currentPromise.then(async () => { |
| 165 | try { |
| 166 | const result = await promise(); |
| 167 | deferred.resolve(result); |
| 168 | } catch (ex) { |
| 169 | deferred.reject(ex); |
| 170 | throw ex; |
| 171 | } |
| 172 | }); |
| 173 | // Wait for previous promises to complete. |
| 174 | await previousPromise; |
| 175 | return deferred.promise; |
| 176 | } |
| 177 | /** |
| 178 | * Chain the provided promise after all previous promises have completed (ignoring errors in previous promises). |
| 179 | */ |
nothing calls this directly
no test coverage detected