Skip to content

Commit

Permalink
Merge pull request #4183 from Agoric/mfig-wallet-timer-fix
Browse files Browse the repository at this point in the history
fix(wallet): properly get the first timerService value
  • Loading branch information
mergify[bot] authored Dec 16, 2021
2 parents e0f7ee8 + 636e099 commit cdf58e6
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions packages/wallet/api/src/date-now.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,28 @@ export const makeTimerServiceDateNow = (
/** @type {PromiseRecord<typeof dateNow>} */
const dateNowPK = makePromiseKit();

// Subscribe to a notifier that will poll the local timer service
// regularly.
const timerNotifier = E(timerService).makeNotifier(0n, timerPollInterval);

// Begin observing the notifier.
observeNotifier(timerNotifier, {
updateState(stamp) {
lastPolledStamp = parseInt(`${stamp}`, 10);
dateNowPK.resolve(dateNow);
},
}).catch(e => dateNowPK.reject(e));
// Observe the timer service regularly.
const observeTimer = async () => {
const observer = {
updateState(stamp) {
lastPolledStamp = parseInt(`${stamp}`, 10);
dateNowPK.resolve(dateNow);
},
};

// Check the current timestamp.
const stamp = await E(timerService).getCurrentTimestamp();
observer.updateState(stamp);

// Subscribe to a notifier that will poll the local timer service
// regularly.
const timerNotifier = E(timerService).makeNotifier(0n, timerPollInterval);

// Begin observing the notifier.
await observeNotifier(timerNotifier, observer);
};

observeTimer().catch(e => dateNowPK.reject(e));

// Return the dateNow function after the notifier fires at least once.
return dateNowPK.promise;
Expand Down

0 comments on commit cdf58e6

Please sign in to comment.