Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: pulling up more await weeds #6744

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/SwingSet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"@endo/zip": "^0.2.28",
"anylogger": "^0.21.0",
"import-meta-resolve": "^1.1.1",
"jessie.js": "^0.3.2",
"microtime": "^3.1.0",
"semver": "^6.3.0"
},
Expand Down
9 changes: 4 additions & 5 deletions packages/SwingSet/src/devices/plugin/device-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export function buildRootDeviceNode(tools) {
* @param {number} epoch which generation of CapTP instances this is
* @returns {Promise<(obj: Record<string, any>) => void>} send a message to the module
*/
async function createConnection(mod, index, epoch) {
try {
const createConnection = async (mod, index, epoch) =>
(async () => {
const modNS = await endowments.import(mod);
const receiver = obj => {
// console.info('receiver', index, obj);
Expand Down Expand Up @@ -87,11 +87,10 @@ export function buildRootDeviceNode(tools) {
const { dispatch } = makeCapTP(mod, receiver, bootstrap, { epoch });

return dispatch;
} catch (e) {
})().catch(e => {
console.error(`Cannot connect to ${mod}:`, e);
throw e;
}
}
});

/**
* Load a module and connect to it.
Expand Down
8 changes: 2 additions & 6 deletions packages/SwingSet/src/vats/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { E } from '@endo/eventual-send';
import { Far } from '@endo/marshal';
import { makePromiseKit } from '@endo/promise-kit';
import { assert, details as X, Fail } from '@agoric/assert';
import { asyncGenerate } from 'jessie.js';
import { whileTrue } from '@agoric/internal';
import { toBytes } from './bytes.js';

import '@agoric/store/exported.js';
Expand Down Expand Up @@ -237,11 +237,7 @@ export function makeNetworkProtocol(protocolHandler) {
const bind = async localAddr => {
// Check if we are underspecified (ends in slash)
const underspecified = localAddr.endsWith(ENDPOINT_SEPARATOR);
const whileUnderspecified = asyncGenerate(() => ({
done: !underspecified,
value: null,
}));
erights marked this conversation as resolved.
Show resolved Hide resolved
for await (const _ of whileUnderspecified) {
for await (const _ of whileTrue(() => underspecified)) {
const portID = await E(protocolHandler).generatePortID(
localAddr,
protocolHandler,
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@agoric/casting": "^0.3.2",
"@agoric/cosmic-proto": "^0.2.1",
"@agoric/ertp": "^0.15.3",
"@agoric/internal": "^0.2.1",
"@agoric/nat": "^4.1.0",
"@agoric/smart-wallet": "^0.4.2",
"@agoric/swingset-vat": "^0.30.2",
Expand All @@ -59,7 +60,6 @@
"deterministic-json": "^1.0.5",
"esm": "agoric-labs/esm#Agoric-built",
"inquirer": "^8.2.2",
"jessie.js": "^0.3.2",
"opener": "^1.5.2",
"tmp": "^0.2.1",
"ws": "^7.2.0"
Expand Down
8 changes: 2 additions & 6 deletions packages/agoric-cli/src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import inquirer from 'inquirer';
import createEsmRequire from 'esm';
import { createRequire } from 'module';
import { SigningStargateClient } from '@cosmjs/stargate';
import { asyncGenerate } from 'jessie.js';
import { whileTrue } from '@agoric/internal';

import { getAccessToken } from '@agoric/access-token';

Expand Down Expand Up @@ -248,11 +248,7 @@ export default async function deployMain(progname, rawArgs, powers, opts) {
let lastUpdateCount;
let stillLoading = [...need].sort();
progressDot = 'o';
const untilNotLoading = asyncGenerate(() => ({
done: !stillLoading.length,
value: stillLoading,
}));
for await (const _ of untilNotLoading) {
for await (const _ of whileTrue(() => stillLoading.length)) {
// Wait for the notifier to report a new state.
process.stdout.write(progressDot);
console.debug('need:', stillLoading.join(', '));
Expand Down
19 changes: 9 additions & 10 deletions packages/agoric-cli/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,14 @@ export default async function initMain(_progname, rawArgs, priv, opts) {
dappBranch = ['-b', opts.dappBranch];
}

if (
await pspawn(
'git',
['clone', '--origin=upstream', dappURL, DIR, ...dappBranch],
{
stdio: 'inherit',
},
)
) {
const exitStatus = await pspawn(
'git',
['clone', '--origin=upstream', dappURL, DIR, ...dappBranch],
{
stdio: 'inherit',
},
);
if (exitStatus) {
throw Error('cannot clone');
}

Expand All @@ -57,7 +56,7 @@ export default async function initMain(_progname, rawArgs, priv, opts) {

let topLevelName;
const subdirs = ['', 'api/', 'contract/', 'ui/', '_agstate/agoric-servers/'];
for (const dir of subdirs) {
for await (const dir of subdirs) {
const path = `${DIR}/${dir}package.json`;
log('rewriting ', path);

Expand Down
55 changes: 25 additions & 30 deletions packages/agoric-cli/src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
}

const yarnInstallEachWorktree = async (phase, ...flags) => {
for (const workTree of workTrees) {
for await (const workTree of workTrees) {
log.info(`yarn install ${phase} in ${workTree}`);
// eslint-disable-next-line no-await-in-loop
const yarnInstall = await pspawn(
Expand Down Expand Up @@ -226,15 +226,14 @@ export default async function installMain(progname, rawArgs, powers, opts) {
}
}
} else {
const subdirPackageJsonExists = async subd => {
const exists = await fs.stat(`${subd}/package.json`).catch(_ => false);
return exists && subd;
};
const existingSubdirs = await Promise.all(
['.', '_agstate/agoric-servers', 'contract', 'api', 'ui']
.sort()
.map(async subd => {
const exists = await fs
.stat(`${subd}/package.json`)
.catch(_ => false);
return exists && subd;
}),
.map(subdirPackageJsonExists),
);
subdirs = existingSubdirs.filter(subd => subd);
}
Expand All @@ -254,22 +253,21 @@ export default async function installMain(progname, rawArgs, powers, opts) {
await fs.symlink(sdkRoot, sdkWorktree);
}

await Promise.all(
subdirs.map(async subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`removing ${nm} link`));
await fs.unlink(nm).catch(_ => {});
const removeNodeModulesSymlinks = async subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`removing ${nm} link`));
await fs.unlink(nm).catch(_ => {});

// Remove all the package links.
// This is needed to prevent yarn errors when installing new versions of
// linked modules (like `@agoric/zoe`).
await Promise.all(
[...sdkPackageToPath.keys()].map(async pjName =>
fs.unlink(`${nm}/${pjName}`).catch(_ => {}),
),
);
}),
);
// Remove all the package links.
// This is needed to prevent yarn errors when installing new versions of
// linked modules (like `@agoric/zoe`).
await Promise.all(
[...sdkPackageToPath.keys()].map(async pjName =>
fs.unlink(`${nm}/${pjName}`).catch(_ => {}),
),
);
};
await Promise.all(subdirs.map(removeNodeModulesSymlinks));
} else {
DEFAULT_SDK_PACKAGE_NAMES.forEach(name => sdkPackageToPath.set(name, null));
}
Expand Down Expand Up @@ -310,17 +308,14 @@ export default async function installMain(progname, rawArgs, powers, opts) {
);

const sdkPackages = [...sdkPackageToPath.keys()].sort();
for (const subdir of subdirs) {
// eslint-disable-next-line no-await-in-loop
for await (const subdir of subdirs) {
const exists = await fs.stat(`${subdir}/package.json`).catch(_ => false);
if (
exists &&
// eslint-disable-next-line no-await-in-loop
(await pspawn('yarn', [...linkFlags, 'link', ...sdkPackages], {
const exitStatus = await (exists &&
pspawn('yarn', [...linkFlags, 'link', ...sdkPackages], {
stdio: 'inherit',
cwd: subdir,
}))
) {
}));
if (exitStatus) {
log.error('Cannot yarn link', ...sdkPackages);
return 1;
}
Expand Down
4 changes: 3 additions & 1 deletion packages/agoric-cli/src/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export default async function walletMain(progname, rawArgs, powers, opts) {
}${suffix}#accessToken=${encodeURIComponent(walletAccessToken)}`;

process.stdout.write(`${walletUrl}\n`);
let p;
if (opts.browser) {
const browser = opener(walletUrl);
await new Promise(resolve => browser.on('exit', resolve));
p = new Promise(resolve => browser.on('exit', resolve));
}
await p;
}
14 changes: 9 additions & 5 deletions packages/agoric-cli/src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,12 @@ export const makeCosmosBundlePublisher = ({

const leader = makeLeaderFromRpcAddresses(rpcAddresses);

const file = await readFile(
pathResolve(homeDirectory, 'ag-solo-mnemonic'),
'ascii',
);
// AWAIT
const mnemonic = (
await readFile(pathResolve(homeDirectory, 'ag-solo-mnemonic'), 'ascii')
).trim();
const mnemonic = file.trim();

const wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, {
prefix: Agoric.Bech32MainPrefix,
Expand Down Expand Up @@ -438,20 +440,21 @@ const publishBundle = async (
const { type } = connectionSpec;
assert.typeof(type, 'string', X`Expected string "type" on connectionSpec`);

let p;
if (type === 'http') {
assertHttpConnectionSpec(connectionSpec);
assert(
publishBundleHttp,
'HTTP installation transaction publisher required',
);
await publishBundleHttp(bundle, connectionSpec);
p = publishBundleHttp(bundle, connectionSpec);
} else if (type === 'chain-cosmos-sdk') {
assertCosmosConnectionSpec(connectionSpec);
assert(
publishBundleCosmos,
'Cosmos SDK installation transaction publisher required',
);
await publishBundleCosmos(bundle, connectionSpec);
p = publishBundleCosmos(bundle, connectionSpec);
} else if (type === 'fake-chain') {
// For the purposes of submitting a bundle to an API like
// E(zoe).install(bundle), in the cases where the publication target does
Expand All @@ -464,6 +467,7 @@ const publishBundle = async (
throw new Error(`Unsupported connection type ${type}`);
}

await p;
return hashBundle;
};

Expand Down
Loading