diff --git a/packages/wallet/api/src/date-now.js b/packages/wallet/api/src/date-now.js index 3d4182ddd1d..44bbcda87f0 100644 --- a/packages/wallet/api/src/date-now.js +++ b/packages/wallet/api/src/date-now.js @@ -29,17 +29,28 @@ export const makeTimerServiceDateNow = ( /** @type {PromiseRecord} */ 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;