diff options
Diffstat (limited to 'packages/taler-wallet-core/src/util/promiseUtils.ts')
-rw-r--r-- | packages/taler-wallet-core/src/util/promiseUtils.ts | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/util/promiseUtils.ts b/packages/taler-wallet-core/src/util/promiseUtils.ts index df4cc343b..d152a12f4 100644 --- a/packages/taler-wallet-core/src/util/promiseUtils.ts +++ b/packages/taler-wallet-core/src/util/promiseUtils.ts @@ -23,6 +23,7 @@ export interface OpenedPromise<T> { promise: Promise<T>; resolve: (val: T) => void; reject: (err: any) => void; + lastError?: any; } /** @@ -33,16 +34,22 @@ export interface OpenedPromise<T> { */ export function openPromise<T>(): OpenedPromise<T> { let resolve: ((x?: any) => void) | null = null; - let reject: ((reason?: any) => void) | null = null; + let promiseReject: ((reason?: any) => void) | null = null; const promise = new Promise<T>((res, rej) => { resolve = res; - reject = rej; + promiseReject = rej; }); - if (!(resolve && reject)) { + if (!(resolve && promiseReject)) { // Never happens, unless JS implementation is broken - throw Error(); + throw Error("JS implementation is broken"); } - return { resolve, reject, promise }; + const result: OpenedPromise<T> = { resolve, reject: promiseReject, promise }; + function saveLastError(reason?: any) { + result.lastError = reason; + promiseReject!(reason); + } + result.reject = saveLastError; + return result; } export class AsyncCondition { |