Skip to content

Commit

Permalink
fix(notifier): make makeStoredSubscription synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Jun 4, 2022
1 parent de03b08 commit e9c23d6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
15 changes: 6 additions & 9 deletions packages/notifier/src/storesub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { E } from '@endo/eventual-send';
import { Far, makeMarshal } from '@endo/marshal';
import { observeIteration } from './asyncIterableAdaptor.js';

/** @template T @typedef {import('@endo/marshal').CapData<T>} CapData */
/** @template T @typedef {import('@endo/eventual-send').EOnly<T>} EOnly */

/**
* Begin iterating the source, publishing serialized iteration values. If the
* publish operation rejects, the iteration will be terminated.
Expand All @@ -15,11 +12,11 @@ import { observeIteration } from './asyncIterableAdaptor.js';
* data out-of-band.
*
* @template T
* @param {ERef<Subscription<T>>} subscription
* @param {Subscription<T>} subscription
* @param {ERef<StorageNode>} [storageNode]
* @param {ERef<ReturnType<typeof makeMarshal>>} [marshaller]
*/
export const makeStoredSubscription = async (
export const makeStoredSubscription = (
subscription,
storageNode,
marshaller = makeMarshal(undefined, undefined, {
Expand Down Expand Up @@ -67,13 +64,13 @@ export const makeStoredSubscription = async (
}).catch(fail);
}

/** @type {EOnly<StoredSubscription<T>>} */
/** @type {StoredSubscription<T>} */
const storesub = Far('StoredSubscription', {
getStoreKey: () => storageNode && E(storageNode).getStoreKey(),
getUnserializer: () => unserializer,
getSharableSubscriptionInternals: () =>
E(subscription).getSharableSubscriptionInternals(),
[Symbol.asyncIterator]: E(subscription)[Symbol.asyncIterator],
getSharableSubscriptionInternals:
subscription.getSharableSubscriptionInternals,
[Symbol.asyncIterator]: subscription[Symbol.asyncIterator],
});
return storesub;
};
Expand Down
6 changes: 4 additions & 2 deletions packages/notifier/test/test-stored-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ const makeFakeStorage = (path, publication) => {
storeName: 'swingset',
storeSubkey: `swingset/data:${fullPath}`,
});
/** @type {Storage} */
return Far('fakeStorage', {
/** @type {StorageNode} */
const storage = Far('fakeStorage', {
getStoreKey: () => storeKey,
setValue: value => {
assert.typeof(value, 'string');
publication.updateState(value);
},
getChildNode: () => storage,
});
return storage;
};

test('stored subscription', async t => {
Expand Down
4 changes: 2 additions & 2 deletions packages/run-protocol/src/vpool-xyk-amm/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
* @property {() => PriceAuthority} getToCentralPriceAuthority
* @property {() => PriceAuthority} getFromCentralPriceAuthority
* @property {() => VirtualPool} getVPool
* @property {() => Subscription<PoolMetricsNotification>} getMetrics
* @property {() => StoredSubscription<PoolMetricsNotification>} getMetrics
*/

/**
Expand Down Expand Up @@ -136,7 +136,7 @@
* Prices and notifications about changing prices.
* @property {() => Brand[]} getAllPoolBrands
* @property {() => Allocation} getProtocolPoolBalance
* @property {() => EOnly<StoredSubscription<MetricsNotification>>} getMetrics
* @property {() => StoredSubscription<MetricsNotification>} getMetrics
* @property {(brand: Brand) => Subscription<PoolMetricsNotification>} getPoolMetrics
*/

Expand Down

0 comments on commit e9c23d6

Please sign in to comment.