Skip to content

Commit

Permalink
refactor: promise-returning function always async
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 6, 2025
1 parent d5baaf8 commit 34fc13a
Show file tree
Hide file tree
Showing 30 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/SwingSet/src/devices/command/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -62,7 +67,7 @@ export function makeNodeSubprocessFactory(tools) {
* @param {import('@agoric/swingset-liveslots').VatDeliveryObject} delivery
* @returns {Promise<import('@agoric/swingset-liveslots').VatDeliveryResult>}
*/
function deliverToWorker(delivery) {
async function deliverToWorker(delivery) {
parentLog(`sending delivery`, delivery);
!waiting || Fail`already waiting for delivery`;
const pr = makePromiseKit();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export function makeXsSubprocessFactory({
}
mk.setDeliverToWorker(deliverToWorker);

function shutdown() {
async function shutdown() {
handleCommandKit?.revoke();
handleCommandKit = undefined;
return worker.close().then(_ => undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/kernel/vat-warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/src/vats/vat-admin/vat-vat-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/vat-admin/broken-hang-vat.js
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion packages/SwingSet/test/vat-admin/new-vat-13.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/SwingSet/test/workers/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion packages/access-token/src/access-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
} = {}) {
Expand Down
4 changes: 2 additions & 2 deletions packages/access-token/src/json-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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');
}
Expand Down
6 changes: 3 additions & 3 deletions packages/agoric-cli/tools/getting-started.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const gettingStartedWorkflowTest = async (t, options = {}) => {
const pkill = (cp, signal = 'SIGINT') => process.kill(-cp.pid, signal);

/** @param {Parameters<typeof pspawn>} args */
function pspawnStdout(...args) {
async function pspawnStdout(...args) {
const ps = pspawn(...args);
const { stdout } = ps.childProcess;
if (stdout) {
Expand All @@ -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' },
Expand All @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/src/launch-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ export async function launch({
* @param {() => Promise<T>} 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);
Expand Down
2 changes: 1 addition & 1 deletion packages/inter-protocol/test/vaultFactory/faucet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/src/lib-nodejs/waitUntilQuiescent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/test/captp-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.');
Expand Down
2 changes: 1 addition & 1 deletion packages/swing-store/test/exportImport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}

Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/src/collectionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions packages/swingset-liveslots/src/liveslots.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1321,7 +1321,7 @@ function build(
* @param {import('./types.js').VatDeliveryObject} delivery
* @returns {undefined | ReturnType<startVat>}
*/
function dispatchToUserspace(delivery) {
async function dispatchToUserspace(delivery) {
let result;
const [type, ...args] = delivery;
switch (type) {
Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/test/gc-and-finalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const makeCollectedResultKit = () => {
};
};

export function watchCollected(target) {
export async function watchCollected(target) {
const kit = makeCollectedResultKit();
fr.register(target, kit);

Expand Down
2 changes: 1 addition & 1 deletion packages/swingset-liveslots/test/waitUntilQuiescent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/wallet/api/src/lib-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ export function makeWalletRoot({
* @param {string} id
* @param {ERef<UserSeat>} seat
*/
function subscribeToUpdates(id, seat) {
async function subscribeToUpdates(id, seat) {
return E(E(seat).getExitSubscriber())
.subscribeAfter()
.then(update => updateOrResubscribe(id, seat, update));
Expand Down Expand Up @@ -1392,7 +1392,7 @@ export function makeWalletRoot({
* @param {string} boardId
* @param {string} [dappOrigin]
*/
function acceptPetname(
async function acceptPetname(
acceptFn,
suggestedPetname,
boardId,
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/api/src/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion packages/xsnap/src/xsrepl.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function main() {
* @param {string} prompt
* @returns {Promise<string>}
*/
function ask(prompt) {
async function ask(prompt) {
const { promise, resolve } = /** @type {PromiseKit<string>} */ (
makePromiseKit()
);
Expand Down
2 changes: 1 addition & 1 deletion packages/xsnap/test/xsnap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/src/contracts/callSpread/payoffHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/test/unitTests/bounty.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const start = async zcf => {
const { oracle, deadline, condition, timer, fee } = zcf.getTerms();

/** @type {(funderSeat: ZCFSeat) => Promise<Invitation>} */
function funder(funderSeat) {
async function funder(funderSeat) {
const endowBounty = harden({
give: { Bounty: null },
});
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/tools/fakePriceAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion packages/zoe/tools/manualPriceAuthority.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function makeManualPriceAuthority(options) {
return floorDivideBy(amountOut, currentPrice);
};

function createQuote(priceQuery) {
async function createQuote(priceQuery) {
if (disabled) {
throw Error('disabled');
}
Expand Down

0 comments on commit 34fc13a

Please sign in to comment.