From 34fc13ad9792fce486aed461c16c6c16dc38f316 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 6 Jan 2025 09:28:40 -0800 Subject: [PATCH] refactor: promise-returning function always async --- packages/SwingSet/src/devices/command/command.js | 2 +- packages/SwingSet/src/kernel/kernel.js | 2 +- .../src/kernel/vat-loader/manager-subprocess-node.js | 11 ++++++++--- .../src/kernel/vat-loader/manager-subprocess-xsnap.js | 2 +- packages/SwingSet/src/kernel/vat-warehouse.js | 2 +- packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js | 2 +- packages/SwingSet/test/vat-admin/broken-hang-vat.js | 2 +- packages/SwingSet/test/vat-admin/new-vat-13.js | 2 +- packages/SwingSet/test/workers/bootstrap.js | 2 +- packages/access-token/src/access-token.js | 2 +- packages/access-token/src/json-store.js | 4 ++-- packages/agoric-cli/tools/getting-started.js | 6 +++--- packages/cosmic-swingset/src/launch-chain.js | 2 +- packages/inter-protocol/test/vaultFactory/faucet.js | 2 +- .../internal/src/lib-nodejs/waitUntilQuiescent.js | 2 +- packages/solo/test/captp-fixture.js | 2 +- packages/swing-store/test/exportImport.test.js | 2 +- packages/swingset-liveslots/src/collectionManager.js | 2 +- packages/swingset-liveslots/src/liveslots.js | 4 ++-- packages/swingset-liveslots/test/gc-and-finalize.js | 2 +- .../swingset-liveslots/test/waitUntilQuiescent.js | 2 +- .../lib/waitUntilQuiescent.js | 2 +- packages/wallet/api/src/lib-wallet.js | 4 ++-- packages/wallet/api/src/wallet.js | 2 +- packages/xsnap/src/xsrepl.js | 2 +- packages/xsnap/test/xsnap.test.js | 2 +- .../zoe/src/contracts/callSpread/payoffHandler.js | 2 +- packages/zoe/test/unitTests/bounty.js | 2 +- packages/zoe/tools/fakePriceAuthority.js | 2 +- packages/zoe/tools/manualPriceAuthority.js | 2 +- 30 files changed, 42 insertions(+), 37 deletions(-) diff --git a/packages/SwingSet/src/devices/command/command.js b/packages/SwingSet/src/devices/command/command.js index d2d3a0e73a9..698942ae78f 100644 --- a/packages/SwingSet/src/devices/command/command.js +++ b/packages/SwingSet/src/devices/command/command.js @@ -9,7 +9,7 @@ export default function buildCommand(broadcastCallback) { let nextCount = 0n; const responses = new Map(); - function inboundCommand(obj) { + async function inboundCommand(obj) { // deliver the JSON-serializable object to the registered handler, and // return a promise that fires with a JSON-serializable object in // response diff --git a/packages/SwingSet/src/kernel/kernel.js b/packages/SwingSet/src/kernel/kernel.js index cd20086dde7..fa6ea8bbc75 100644 --- a/packages/SwingSet/src/kernel/kernel.js +++ b/packages/SwingSet/src/kernel/kernel.js @@ -2043,7 +2043,7 @@ export default function buildKernel( } // mostly used by tests, only needed with thread/process-based workers - function shutdown() { + async function shutdown() { return vatWarehouse.shutdown(); } diff --git a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-node.js b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-node.js index 9cfad88feb7..c2e40d3e1dc 100644 --- a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-node.js +++ b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-node.js @@ -16,7 +16,12 @@ function parentLog(first, ...args) { export function makeNodeSubprocessFactory(tools) { const { startSubprocessWorker, testLog } = tools; - function createFromBundle(vatID, bundle, managerOptions, liveSlotsOptions) { + async function createFromBundle( + vatID, + bundle, + managerOptions, + liveSlotsOptions, + ) { assert(!managerOptions.enableSetup, 'not supported at all'); assert( managerOptions.useTranscript, @@ -62,7 +67,7 @@ export function makeNodeSubprocessFactory(tools) { * @param {import('@agoric/swingset-liveslots').VatDeliveryObject} delivery * @returns {Promise} */ - function deliverToWorker(delivery) { + async function deliverToWorker(delivery) { parentLog(`sending delivery`, delivery); !waiting || Fail`already waiting for delivery`; const pr = makePromiseKit(); @@ -107,7 +112,7 @@ export function makeNodeSubprocessFactory(tools) { parentLog(`instructing worker to load bundle..`); sendToWorker(['setBundle', vatID, bundle, liveSlotsOptions]); - function shutdown() { + async function shutdown() { // terminate(); // XXX currently disabled since it breaks profiling; we should revisit if we develop a problem with worker vat processes refusing to exit when requested to do so sendToWorker(['exit']); return E.when(done, _ => undefined); diff --git a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js index ff9a4bb1d50..48a3d673231 100644 --- a/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js +++ b/packages/SwingSet/src/kernel/vat-loader/manager-subprocess-xsnap.js @@ -226,7 +226,7 @@ export function makeXsSubprocessFactory({ } mk.setDeliverToWorker(deliverToWorker); - function shutdown() { + async function shutdown() { handleCommandKit?.revoke(); handleCommandKit = undefined; return worker.close().then(_ => undefined); diff --git a/packages/SwingSet/src/kernel/vat-warehouse.js b/packages/SwingSet/src/kernel/vat-warehouse.js index 2c2dbe07377..3dfb49bfe2b 100644 --- a/packages/SwingSet/src/kernel/vat-warehouse.js +++ b/packages/SwingSet/src/kernel/vat-warehouse.js @@ -686,7 +686,7 @@ export function makeVatWarehouse({ } // mostly used by tests, only needed with thread/process-based workers - function shutdown() { + async function shutdown() { const work = Array.from(ephemeral.vats.values(), ({ manager }) => manager.shutdown(), ); diff --git a/packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js b/packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js index 675db94cbb1..fdcfd112fcb 100644 --- a/packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js +++ b/packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js @@ -322,7 +322,7 @@ export function buildRootObject(vatPowers, _vatParameters, baggage) { }, ); - function finishVatCreation(vatID) { + async function finishVatCreation(vatID) { const [pendingP, pendingRR] = producePRR(); pendingVatCreations.set(vatID, pendingRR); diff --git a/packages/SwingSet/test/vat-admin/broken-hang-vat.js b/packages/SwingSet/test/vat-admin/broken-hang-vat.js index 01d1b56d8f0..373abc6027e 100644 --- a/packages/SwingSet/test/vat-admin/broken-hang-vat.js +++ b/packages/SwingSet/test/vat-admin/broken-hang-vat.js @@ -1,6 +1,6 @@ import { makePromiseKit } from '@endo/promise-kit'; -export function buildRootObject() { +export async function buildRootObject() { const pk = makePromiseKit(); return pk.promise; // never resolves } diff --git a/packages/SwingSet/test/vat-admin/new-vat-13.js b/packages/SwingSet/test/vat-admin/new-vat-13.js index 6d32acce6fe..d00d4e1332f 100644 --- a/packages/SwingSet/test/vat-admin/new-vat-13.js +++ b/packages/SwingSet/test/vat-admin/new-vat-13.js @@ -1,6 +1,6 @@ import { Far, E } from '@endo/far'; -export function buildRootObject(_vatPowers, vatParameters) { +export async function buildRootObject(_vatPowers, vatParameters) { const { adder } = vatParameters; function rcvrMaker(seed) { let count = 0; diff --git a/packages/SwingSet/test/workers/bootstrap.js b/packages/SwingSet/test/workers/bootstrap.js index bcbad1a1478..f88e2dc6f62 100644 --- a/packages/SwingSet/test/workers/bootstrap.js +++ b/packages/SwingSet/test/workers/bootstrap.js @@ -46,7 +46,7 @@ export function buildRootObject() { return three === 3 ? 'three good' : `not three, got ${three}`; } - function checkA([pB, pC, pF, three, evt, evwft]) { + async function checkA([pB, pC, pF, three, evt, evwft]) { return Promise.all([ pB.then(checkResB), pC.then(checkResC, checkErrC), diff --git a/packages/access-token/src/access-token.js b/packages/access-token/src/access-token.js index 812b2ee7d04..29923a6b687 100644 --- a/packages/access-token/src/access-token.js +++ b/packages/access-token/src/access-token.js @@ -11,7 +11,7 @@ import { openJSONStore } from './json-store.js'; * @param {BufferEncoding} [opts.stringBase] * @param {number} [opts.byteLength] */ -export function generateAccessToken({ +export async function generateAccessToken({ stringBase = 'base64url', byteLength = 48, } = {}) { diff --git a/packages/access-token/src/json-store.js b/packages/access-token/src/json-store.js index a4ea82ab69a..7b9c64b1f23 100644 --- a/packages/access-token/src/json-store.js +++ b/packages/access-token/src/json-store.js @@ -270,7 +270,7 @@ async function makeJSONStore( * // changes * } */ -export function initJSONStore(dirPath) { +export async function initJSONStore(dirPath) { if (dirPath !== null && dirPath !== undefined && `${dirPath}` !== dirPath) { throw Error('dirPath must be a string or nullish'); } @@ -294,7 +294,7 @@ export function initJSONStore(dirPath) { * // changes * } */ -export function openJSONStore(dirPath) { +export async function openJSONStore(dirPath) { if (`${dirPath}` !== dirPath) { throw Error('dirPath must be a string'); } diff --git a/packages/agoric-cli/tools/getting-started.js b/packages/agoric-cli/tools/getting-started.js index f294fb653ed..ab43ae456b0 100644 --- a/packages/agoric-cli/tools/getting-started.js +++ b/packages/agoric-cli/tools/getting-started.js @@ -77,7 +77,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => { const pkill = (cp, signal = 'SIGINT') => process.kill(-cp.pid, signal); /** @param {Parameters} args */ - function pspawnStdout(...args) { + async function pspawnStdout(...args) { const ps = pspawn(...args); const { stdout } = ps.childProcess; if (stdout) { @@ -99,7 +99,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => { }; const { AGORIC_CMD = JSON.stringify(defaultAgoricCmd()) } = process.env; const agoricCmd = JSON.parse(AGORIC_CMD); - function myMain(args, opts = {}) { + async function myMain(args, opts = {}) { return pspawnStdout(agoricCmd[0], [...agoricCmd.slice(1), ...args], { stdio: ['ignore', 'pipe', 'inherit'], env: { ...process.env, DEBUG: 'agoric:debug' }, @@ -108,7 +108,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => { }); } - function yarn(args) { + async function yarn(args) { return pspawnStdout('yarn', args, { stdio: ['ignore', 'pipe', 'inherit'], env: { ...process.env }, diff --git a/packages/cosmic-swingset/src/launch-chain.js b/packages/cosmic-swingset/src/launch-chain.js index eccfbbc2a65..2db547519d9 100644 --- a/packages/cosmic-swingset/src/launch-chain.js +++ b/packages/cosmic-swingset/src/launch-chain.js @@ -816,7 +816,7 @@ export async function launch({ * @param {() => Promise} fn * @param {() => void} onSettled */ - function withErrorLogging(label, fn, onSettled) { + async function withErrorLogging(label, fn, onSettled) { const p = fn(); void E.when(p, onSettled, err => { blockManagerConsole.error(label, 'error:', err); diff --git a/packages/inter-protocol/test/vaultFactory/faucet.js b/packages/inter-protocol/test/vaultFactory/faucet.js index 1edee2d1eaf..c1bf2857318 100644 --- a/packages/inter-protocol/test/vaultFactory/faucet.js +++ b/packages/inter-protocol/test/vaultFactory/faucet.js @@ -11,7 +11,7 @@ import { assertProposalShape } from '@agoric/zoe/src/contractSupport/index.js'; export async function start(zcf, { feeMintAccess }) { const stableMint = await zcf.registerFeeMint('RUN', feeMintAccess); - function makeFaucetInvitation() { + async function makeFaucetInvitation() { /** @param {ZCFSeat} seat */ async function faucetHook(seat) { assertProposalShape(seat, { want: { RUN: null } }); diff --git a/packages/internal/src/lib-nodejs/waitUntilQuiescent.js b/packages/internal/src/lib-nodejs/waitUntilQuiescent.js index f0b5794552b..7d1d9012997 100644 --- a/packages/internal/src/lib-nodejs/waitUntilQuiescent.js +++ b/packages/internal/src/lib-nodejs/waitUntilQuiescent.js @@ -4,7 +4,7 @@ import { makePromiseKit } from '@endo/promise-kit'; // This can only be imported from the Start Compartment, where 'setImmediate' // is available. -export function waitUntilQuiescent() { +export async function waitUntilQuiescent() { // the delivery might cause some number of (native) Promises to be // created and resolved, so we use the IO queue to detect when the // Promise queue is empty. The IO queue (setImmediate and setTimeout) is diff --git a/packages/solo/test/captp-fixture.js b/packages/solo/test/captp-fixture.js index 4df0da6c838..3651eb5a600 100644 --- a/packages/solo/test/captp-fixture.js +++ b/packages/solo/test/captp-fixture.js @@ -36,7 +36,7 @@ export async function makeFixture(PORT, noisy = false) { /** @type {WebSocket} */ let ws; - function connect() { + async function connect() { process.stdout.write('# connecting'); async function tryConnect(resolve, reject) { process.stdout.write('.'); diff --git a/packages/swing-store/test/exportImport.test.js b/packages/swing-store/test/exportImport.test.js index 2458de32c55..dcf888de7e4 100644 --- a/packages/swing-store/test/exportImport.test.js +++ b/packages/swing-store/test/exportImport.test.js @@ -314,7 +314,7 @@ async function testExportImport( t.deepEqual(artifactNames, expectedArtifactNames); const beforeDump = debug.dump(keepSnapshots); - function doImport() { + async function doImport() { return importSwingStore(exporter, null, { artifactMode: importMode }); } diff --git a/packages/swingset-liveslots/src/collectionManager.js b/packages/swingset-liveslots/src/collectionManager.js index 69dfc18531d..74e8a9b0e0f 100644 --- a/packages/swingset-liveslots/src/collectionManager.js +++ b/packages/swingset-liveslots/src/collectionManager.js @@ -356,7 +356,7 @@ export function makeCollectionManager( return prefix(encodedKey); } - function dbKeyToKey(dbKey) { + async function dbKeyToKey(dbKey) { // convert e.g. vc.5.r0000000001:o+v10/1 to r0000000001:o+v10/1 const dbEntryKey = dbKey.substring(dbKeyPrefix.length); return decodeKey(dbEntryKey); diff --git a/packages/swingset-liveslots/src/liveslots.js b/packages/swingset-liveslots/src/liveslots.js index b0d82478a8f..d6951d2fe85 100644 --- a/packages/swingset-liveslots/src/liveslots.js +++ b/packages/swingset-liveslots/src/liveslots.js @@ -706,7 +706,7 @@ function build( }; } - function queueMessage(targetSlot, prop, args, returnedP) { + async function queueMessage(targetSlot, prop, args, returnedP) { const methargs = [prop, args]; meterControl.assertIsMetered(); // else userspace getters could escape @@ -1321,7 +1321,7 @@ function build( * @param {import('./types.js').VatDeliveryObject} delivery * @returns {undefined | ReturnType} */ - function dispatchToUserspace(delivery) { + async function dispatchToUserspace(delivery) { let result; const [type, ...args] = delivery; switch (type) { diff --git a/packages/swingset-liveslots/test/gc-and-finalize.js b/packages/swingset-liveslots/test/gc-and-finalize.js index 8df976deee3..d50a176b328 100644 --- a/packages/swingset-liveslots/test/gc-and-finalize.js +++ b/packages/swingset-liveslots/test/gc-and-finalize.js @@ -112,7 +112,7 @@ const makeCollectedResultKit = () => { }; }; -export function watchCollected(target) { +export async function watchCollected(target) { const kit = makeCollectedResultKit(); fr.register(target, kit); diff --git a/packages/swingset-liveslots/test/waitUntilQuiescent.js b/packages/swingset-liveslots/test/waitUntilQuiescent.js index 1f36df969db..4bbd83fd5bf 100644 --- a/packages/swingset-liveslots/test/waitUntilQuiescent.js +++ b/packages/swingset-liveslots/test/waitUntilQuiescent.js @@ -6,7 +6,7 @@ import { makePromiseKit } from '@endo/promise-kit'; // This can only be imported from the Start Compartment, where 'setImmediate' // is available. -export function waitUntilQuiescent() { +export async function waitUntilQuiescent() { // the delivery might cause some number of (native) Promises to be // created and resolved, so we use the IO queue to detect when the // Promise queue is empty. The IO queue (setImmediate and setTimeout) is diff --git a/packages/swingset-xsnap-supervisor/lib/waitUntilQuiescent.js b/packages/swingset-xsnap-supervisor/lib/waitUntilQuiescent.js index f0b5794552b..7d1d9012997 100644 --- a/packages/swingset-xsnap-supervisor/lib/waitUntilQuiescent.js +++ b/packages/swingset-xsnap-supervisor/lib/waitUntilQuiescent.js @@ -4,7 +4,7 @@ import { makePromiseKit } from '@endo/promise-kit'; // This can only be imported from the Start Compartment, where 'setImmediate' // is available. -export function waitUntilQuiescent() { +export async function waitUntilQuiescent() { // the delivery might cause some number of (native) Promises to be // created and resolved, so we use the IO queue to detect when the // Promise queue is empty. The IO queue (setImmediate and setTimeout) is diff --git a/packages/wallet/api/src/lib-wallet.js b/packages/wallet/api/src/lib-wallet.js index 5ca726cfd89..fd4cd78b720 100644 --- a/packages/wallet/api/src/lib-wallet.js +++ b/packages/wallet/api/src/lib-wallet.js @@ -586,7 +586,7 @@ export function makeWalletRoot({ * @param {string} id * @param {ERef} seat */ - function subscribeToUpdates(id, seat) { + async function subscribeToUpdates(id, seat) { return E(E(seat).getExitSubscriber()) .subscribeAfter() .then(update => updateOrResubscribe(id, seat, update)); @@ -1392,7 +1392,7 @@ export function makeWalletRoot({ * @param {string} boardId * @param {string} [dappOrigin] */ - function acceptPetname( + async function acceptPetname( acceptFn, suggestedPetname, boardId, diff --git a/packages/wallet/api/src/wallet.js b/packages/wallet/api/src/wallet.js index 7efc95ede75..152262fb375 100644 --- a/packages/wallet/api/src/wallet.js +++ b/packages/wallet/api/src/wallet.js @@ -670,7 +670,7 @@ export function buildRootObject(vatPowers) { * @param {StartupTerms} terms * @param {*} _inviteMaker */ -export default function spawn(terms, _inviteMaker) { +export default async function spawn(terms, _inviteMaker) { const walletVat = buildRootObject(); return walletVat.startup(terms).then(_ => walletVat); } diff --git a/packages/xsnap/src/xsrepl.js b/packages/xsnap/src/xsrepl.js index f27cf446740..0bd75d88072 100755 --- a/packages/xsnap/src/xsrepl.js +++ b/packages/xsnap/src/xsrepl.js @@ -62,7 +62,7 @@ async function main() { * @param {string} prompt * @returns {Promise} */ - function ask(prompt) { + async function ask(prompt) { const { promise, resolve } = /** @type {PromiseKit} */ ( makePromiseKit() ); diff --git a/packages/xsnap/test/xsnap.test.js b/packages/xsnap/test/xsnap.test.js index 3b58edbf1b3..063c43076f5 100644 --- a/packages/xsnap/test/xsnap.test.js +++ b/packages/xsnap/test/xsnap.test.js @@ -381,7 +381,7 @@ test('execute immediately after makeSnapshotStream', async t => { t.deepEqual(messages, ['before']); }); -function delay(ms) { +async function delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } diff --git a/packages/zoe/src/contracts/callSpread/payoffHandler.js b/packages/zoe/src/contracts/callSpread/payoffHandler.js index 5825b494bab..61ef0499e91 100644 --- a/packages/zoe/src/contracts/callSpread/payoffHandler.js +++ b/packages/zoe/src/contracts/callSpread/payoffHandler.js @@ -27,7 +27,7 @@ function makePayoffHandler(zcf, seatPromiseKits, collateralSeat) { let seatsExited = 0; /** @type {MakeOptionInvitation} */ - function makeOptionInvitation(position) { + async function makeOptionInvitation(position) { return zcf.makeInvitation( // All we do at the time of exercise is resolve the promise. seat => seatPromiseKits[position].resolve(seat), diff --git a/packages/zoe/test/unitTests/bounty.js b/packages/zoe/test/unitTests/bounty.js index bfec6ca4185..7ad23d71c3e 100644 --- a/packages/zoe/test/unitTests/bounty.js +++ b/packages/zoe/test/unitTests/bounty.js @@ -22,7 +22,7 @@ const start = async zcf => { const { oracle, deadline, condition, timer, fee } = zcf.getTerms(); /** @type {(funderSeat: ZCFSeat) => Promise} */ - function funder(funderSeat) { + async function funder(funderSeat) { const endowBounty = harden({ give: { Bounty: null }, }); diff --git a/packages/zoe/tools/fakePriceAuthority.js b/packages/zoe/tools/fakePriceAuthority.js index f7b24db3ec6..ce649af01b2 100644 --- a/packages/zoe/tools/fakePriceAuthority.js +++ b/packages/zoe/tools/fakePriceAuthority.js @@ -242,7 +242,7 @@ export async function makeFakePriceAuthority(options) { latestTick = timestamp; } - function resolveQuoteWhen(operator, amountIn, amountOutLimit) { + async function resolveQuoteWhen(operator, amountIn, amountOutLimit) { assertBrands(amountIn.brand, amountOutLimit.brand); const promiseKit = makePromiseKit(); const req = { diff --git a/packages/zoe/tools/manualPriceAuthority.js b/packages/zoe/tools/manualPriceAuthority.js index 9203130fc7e..51794ebd9d9 100644 --- a/packages/zoe/tools/manualPriceAuthority.js +++ b/packages/zoe/tools/manualPriceAuthority.js @@ -55,7 +55,7 @@ export function makeManualPriceAuthority(options) { return floorDivideBy(amountOut, currentPrice); }; - function createQuote(priceQuery) { + async function createQuote(priceQuery) { if (disabled) { throw Error('disabled'); }