summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/remote.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/remote.ts')
-rw-r--r--packages/taler-wallet-core/src/remote.ts30
1 files changed, 16 insertions, 14 deletions
diff --git a/packages/taler-wallet-core/src/remote.ts b/packages/taler-wallet-core/src/remote.ts
index 2628fea07..bc0be9d30 100644
--- a/packages/taler-wallet-core/src/remote.ts
+++ b/packages/taler-wallet-core/src/remote.ts
@@ -145,9 +145,14 @@ export function getClientFromRemoteWallet(
export interface WalletNotificationWaiter {
notify(wn: WalletNotification): void;
- waitForNotificationCond(
- cond: (n: WalletNotification) => boolean,
- ): Promise<void>;
+ waitForNotificationCond<T>(
+ cond: (n: WalletNotification) => T | false | undefined,
+ ): Promise<T>;
+}
+
+interface NotificationCondEntry<T> {
+ condition: (n: WalletNotification) => T | false | undefined;
+ promiseCapability: OpenedPromise<T>;
}
/**
@@ -157,22 +162,19 @@ export interface WalletNotificationWaiter {
export function makeNotificationWaiter(): WalletNotificationWaiter {
// Bookkeeping for waiting on notification conditions
let nextCondIndex = 1;
- const condMap: Map<
- number,
- {
- condition: (n: WalletNotification) => boolean;
- promiseCapability: OpenedPromise<void>;
- }
- > = new Map();
+ const condMap: Map<number, NotificationCondEntry<any>> = new Map();
function onNotification(n: WalletNotification) {
condMap.forEach((cond, condKey) => {
- if (cond.condition(n)) {
- cond.promiseCapability.resolve();
+ const res = cond.condition(n);
+ if (res) {
+ cond.promiseCapability.resolve(res);
}
});
}
- function waitForNotificationCond(cond: (n: WalletNotification) => boolean) {
- const promCap = openPromise<void>();
+ function waitForNotificationCond<T>(
+ cond: (n: WalletNotification) => T | false | undefined,
+ ) {
+ const promCap = openPromise<T>();
condMap.set(nextCondIndex++, {
condition: cond,
promiseCapability: promCap,