Skip to content

Commit

Permalink
refactor: recur watchPurse
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 28, 2023
1 parent 5881942 commit b3cb5b3
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions packages/smart-wallet/src/smartWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,24 +443,20 @@ export const prepareSmartWallet = (baggage, shared) => {

// This would seem to fit the observeNotifier() pattern,
// but purse notifiers are not (always) durable.
// outer loop: for each upgrade disconnection...
for (;;) {
const notifier = E(purse).getCurrentAmountNotifier();
try {
// eslint-disable-next-line no-await-in-loop
for await (const newBalance of subscribeLatestSimple(notifier)) {
helper.updateBalance(purse, newBalance);
}
} catch (err) {
if (isUpgradeDisconnection(err)) {
continue; // retry
}
console.error(
`*** ${address} failed amount observer, ${err} ***`,
);
// TODO: think about API change.
throw err;
// If there is an error due to upgrade, retry watchPurse().
const notifier = E(purse).getCurrentAmountNotifier();
try {
// eslint-disable-next-line no-await-in-loop
for await (const newBalance of subscribeLatestSimple(notifier)) {
helper.updateBalance(purse, newBalance);
}
} catch (err) {
if (isUpgradeDisconnection(err)) {
helper.watchPurse(purse); // retry
}
console.error(`*** ${address} failed amount observer, ${err} ***`);
// TODO: think about API change.
throw err;
}
},

Expand Down

0 comments on commit b3cb5b3

Please sign in to comment.