Skip to content

Commit

Permalink
chore(wallet-tools): notifier -> async iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Feb 22, 2024
1 parent 3c7e212 commit 9e3d865
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions contract/test/wallet-tools.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check
import { E, Far } from '@endo/far';
import { makePromiseKit } from '@endo/promise-kit';
import { makeNotifier } from '@agoric/notifier';
import { allValues, mapValues } from '../src/objectTools.js';

export { allValues, mapValues };
Expand Down Expand Up @@ -162,15 +163,20 @@ export const mockWalletFactory = (
};
}

async function* purseUpdates(brand) {
const n = makeNotifier(
E(
purseByBrand.get(brand) || Fail`${q(brand)}`,
).getCurrentAmountNotifier(),
);
for await (const amount of n) {
yield amount;
}
}
return {
deposit: depositFacet,
offers: Far('Offers', { executeOffer, addIssuer, tryExit }),
peek: Far('Wallet Peek', {
purseNotifier: brand =>
E(
purseByBrand.get(brand) || Fail`${q(brand)}`,
).getCurrentAmountNotifier(),
}),
peek: Far('Wallet Peek', { purseUpdates }),
};
};

Expand All @@ -187,6 +193,7 @@ export const seatLike = updates => {
payouts: makePromiseKit(),
};
(async () => {
await null;
try {
// XXX an error here is somehow and unhandled rejection
for await (const update of updates) {
Expand Down

0 comments on commit 9e3d865

Please sign in to comment.