Skip to content

Commit

Permalink
chore(types): watchPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Nov 9, 2023
1 parent 5707827 commit d9994a3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
7 changes: 5 additions & 2 deletions packages/swingset-liveslots/src/vatDataTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
WeakMapStore,
WeakSetStore,
} from '@agoric/store';
import type { makeWatchedPromiseManager } from './watchedPromises.js';

// TODO should be moved into @endo/patterns and eventually imported here
// instead of this local definition.
Expand All @@ -25,6 +26,8 @@ export type { MapStore, Pattern };
// onerous.
export type Baggage = MapStore<string, any>;

type WatchedPromisesManager = ReturnType<typeof makeWatchedPromiseManager>;

type Tail<T extends any[]> = T extends [head: any, ...rest: infer Rest]
? Rest
: [];
Expand Down Expand Up @@ -169,8 +172,8 @@ export type VatData = {
options?: DefineKindOptions<MultiKindContext<S, B>>,
) => (...args: P) => KindFacets<B>;

providePromiseWatcher: unknown;
watchPromise: unknown;
providePromiseWatcher: WatchedPromisesManager['providePromiseWatcher'];
watchPromise: WatchedPromisesManager['watchPromise'];

makeScalarBigMapStore: <K, V>(
label: string,
Expand Down
6 changes: 6 additions & 0 deletions packages/swingset-liveslots/src/watchedPromises.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ export function makeWatchedPromiseManager({
}
}

/**
*
* @param {Promise} p
* @param {{onFulfilled?: Function, onRejected?: Function}} watcher
* @param {...any} args
*/
function watchPromise(p, watcher, ...args) {
// The following wrapping defers setting up the promise watcher itself to a
// later turn so that if the promise to be watched was the return value from
Expand Down
3 changes: 2 additions & 1 deletion packages/swingset-liveslots/tools/setup-vat-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ globalThis.VatData = harden({
canBeDurable: (...args) => fakeVomKit.vom.canBeDurable(...args),
providePromiseWatcher: (...args) =>
fakeVomKit.wpm.providePromiseWatcher(...args),
watchPromise: (...args) => fakeVomKit.wpm.watchPromise(...args),
watchPromise: (p, watcher, ...args) =>
fakeVomKit.wpm.watchPromise(p, watcher, ...args),
makeScalarBigMapStore: (...args) =>
fakeVomKit.cm.makeScalarBigMapStore(...args),
makeScalarBigWeakMapStore: (...args) =>
Expand Down
10 changes: 2 additions & 8 deletions packages/zoe/src/zoeService/startInstance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* global globalThis */

/* eslint @typescript-eslint/no-floating-promises: "warn" */
import { E } from '@endo/eventual-send';
import { passStyleOf } from '@endo/marshal';
Expand All @@ -9,6 +7,7 @@ import {
provideDurableWeakMapStore,
prepareExoClass,
prepareExo,
watchPromise,
} from '@agoric/vat-data';
import { initEmpty } from '@agoric/store';
import { isUpgradeDisconnection } from '@agoric/internal/src/upgrade-api.js';
Expand Down Expand Up @@ -92,12 +91,7 @@ export const makeStartInstance = (
);

const watchForAdminNodeDone = (adminNode, instAdmin) => {
globalThis.VatData.watchPromise(
E(adminNode).done(),
watcher,
instAdmin,
adminNode,
);
watchPromise(E(adminNode).done(), watcher, instAdmin, adminNode);
};

const makeZoeInstanceAdmin = prepareExoClass(
Expand Down

0 comments on commit d9994a3

Please sign in to comment.