diff --git a/packages/inter-protocol/src/vaultFactory/vaultManager.js b/packages/inter-protocol/src/vaultFactory/vaultManager.js index 40006d5acd0e..8f023a8d72e8 100644 --- a/packages/inter-protocol/src/vaultFactory/vaultManager.js +++ b/packages/inter-protocol/src/vaultFactory/vaultManager.js @@ -27,11 +27,7 @@ import { RatioShape, } from '@agoric/ertp'; import { makeTracer } from '@agoric/internal'; -import { - makeStoredNotifier, - observeNotifier, - watchPerpetualNotifier, -} from '@agoric/notifier'; +import { makeStoredNotifier, observeNotifier } from '@agoric/notifier'; import { appendToStoredArray } from '@agoric/store/src/stores/store-utils.js'; import { M, @@ -73,6 +69,38 @@ const { details: X, Fail, quote: q } = assert; const trace = makeTracer('VM'); +/** + * Watch a notifier that isn't expected to fail or finish unless the vat hosting + * the notifier is upgraded. This watcher supports that by providing a + * straightforward way to get a replacement if the notifier breaks. + * + * @template T notifier topic + * @template {any[]} [A=unknown[]] arbitrary arguments + * @param {ERef>} notifierP + * @param {import('@agoric/swingset-liveslots').PromiseWatcher} watcher + * @param {A} args + */ +export const watchQuoteNotifier = async (notifierP, watcher, ...args) => { + await undefined; + + let updateCount; + for (;;) { + let value; + try { + ({ value, updateCount } = await E(notifierP).getUpdateSince(updateCount)); + watcher.onFulfilled && watcher.onFulfilled(value, ...args); + } catch (e) { + watcher.onRejected && watcher.onRejected(e, ...args); + break; + } + if (updateCount === undefined) { + watcher.onRejected && + watcher.onRejected(Error('stream finished'), ...args); + break; + } + } +}; + /** @typedef {import('./storeUtils.js').NormalizedDebt} NormalizedDebt */ /** @typedef {import('@agoric/time').RelativeTime} RelativeTime */ diff --git a/packages/notifier/src/asyncIterableAdaptor.js b/packages/notifier/src/asyncIterableAdaptor.js index db0748cc266c..b8ab685496d2 100644 --- a/packages/notifier/src/asyncIterableAdaptor.js +++ b/packages/notifier/src/asyncIterableAdaptor.js @@ -103,35 +103,3 @@ export const observeIteration = (asyncIterableP, iterationObserver) => { */ export const observeNotifier = (notifierP, iterationObserver) => observeIteration(subscribeLatest(notifierP), iterationObserver); - -/** - * Watch an ephemeral notifier, and recover if it fails due to upgrade or other - * reasons. Since it's expected to be a perpetual notifier, the watcher's - * onRejected will also be called if the notifier calls finish(). - * - * @template T notifier topic - * @template {any[]} [A=unknown[]] arbitrary arguments - * @param {ERef>} notifierP - * @param {import('@agoric/swingset-liveslots').PromiseWatcher} watcher - * @param {A} args - */ -export const watchPerpetualNotifier = async (notifierP, watcher, ...args) => { - await undefined; - - let updateCount; - for (;;) { - let value; - try { - ({ value, updateCount } = await E(notifierP).getUpdateSince(updateCount)); - watcher.onFulfilled && watcher.onFulfilled(value, ...args); - } catch (e) { - watcher.onRejected && watcher.onRejected(e, ...args); - break; - } - if (updateCount === undefined) { - watcher.onRejected && - watcher.onRejected(Error('stream finished'), ...args); - break; - } - } -}; diff --git a/packages/notifier/src/index.js b/packages/notifier/src/index.js index db8f8e0eae43..4402bee78843 100644 --- a/packages/notifier/src/index.js +++ b/packages/notifier/src/index.js @@ -20,7 +20,6 @@ export { observeNotifier, observeIterator, observeIteration, - watchPerpetualNotifier, // deprecated, consider removing makeAsyncIterableFromNotifier, } from './asyncIterableAdaptor.js';