Skip to content

Commit

Permalink
refactor(daemon): Make makeControllerForFormula synchronous
Browse files Browse the repository at this point in the history
Makes `makeControllerForFormula` and its dependent functions
synchronous. Also performs some unused parameter cleanup.
  • Loading branch information
rekmarks committed Feb 21, 2024
1 parent 8b289f0 commit 80516f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
24 changes: 10 additions & 14 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ const makeInspector = (type, number, record) =>
* @param {import('./types.js').DaemonicPowers} powers
* @param {Promise<number>} webletPortP
* @param {object} args
* @param {Promise<never>} args.cancelled
* @param {(error: Error) => void} args.cancel
* @param {number} args.gracePeriodMs
* @param {Promise<never>} args.gracePeriodElapsed
*/
const makeDaemonCore = async (
powers,
webletPortP,
{ cancelled, cancel, gracePeriodMs, gracePeriodElapsed },
{ cancel, gracePeriodMs, gracePeriodElapsed },
) => {
const {
crypto: cryptoPowers,
Expand Down Expand Up @@ -336,7 +335,7 @@ const makeDaemonCore = async (
* @param {import('./types.js').Formula} formula
* @param {import('./types.js').Context} context
*/
const makeControllerForFormula = async (
const makeControllerForFormula = (
formulaIdentifier,
formulaNumber,
formula,
Expand Down Expand Up @@ -622,15 +621,16 @@ const makeDaemonCore = async (
};

/** @type {import('./types.js').ProvideValueForFormulaIdentifier} */
const provideValueForFormulaIdentifier = async formulaIdentifier => {
const provideValueForFormulaIdentifier = formulaIdentifier => {
const controller = /** @type {import('./types.js').Controller<>} */ (
provideControllerForFormulaIdentifier(formulaIdentifier)
);
const value = await controller.external;
if (typeof value === 'object' && value !== null) {
formulaIdentifierForRef.set(value, formulaIdentifier);
}
return value;
return controller.external.then(value => {
if (typeof value === 'object' && value !== null) {
formulaIdentifierForRef.set(value, formulaIdentifier);
}
return value;
});
};

/** @type {import('./types.js').ProvideControllerForFormulaIdentifierAndResolveHandle} */
Expand Down Expand Up @@ -1010,7 +1010,6 @@ const makeDaemonCore = async (
incarnateWebBundle,
incarnateHandle,
storeReaderRef,
randomHex512,
makeMailbox,
});

Expand Down Expand Up @@ -1159,7 +1158,6 @@ const makeDaemonCore = async (
* @param {import('./types.js').DaemonicPowers} powers
* @param {Promise<number>} webletPortP
* @param {object} args
* @param {Promise<never>} args.cancelled
* @param {(error: Error) => void} args.cancel
* @param {number} args.gracePeriodMs
* @param {Promise<never>} args.gracePeriodElapsed
Expand All @@ -1168,12 +1166,11 @@ const makeDaemonCore = async (
const provideEndoBootstrap = async (
powers,
webletPortP,
{ cancelled, cancel, gracePeriodMs, gracePeriodElapsed },
{ cancel, gracePeriodMs, gracePeriodElapsed },
) => {
const { persistence: persistencePowers } = powers;

const daemonCore = await makeDaemonCore(powers, webletPortP, {
cancelled,
cancel,
gracePeriodMs,
gracePeriodElapsed,
Expand Down Expand Up @@ -1228,7 +1225,6 @@ export const makeDaemon = async (powers, daemonLabel, cancel, cancelled) => {
powers,
assignedWebletPortP,
{
cancelled,
cancel,
gracePeriodMs,
gracePeriodElapsed,
Expand Down
1 change: 0 additions & 1 deletion packages/daemon/src/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const makeHostMaker = ({
incarnateWebBundle,
incarnateHandle,
storeReaderRef,
randomHex512,
makeMailbox,
}) => {
/**
Expand Down

0 comments on commit 80516f7

Please sign in to comment.