Skip to content

Commit

Permalink
refactor(daemon): Id means formula identifier (merge #2151)
Browse files Browse the repository at this point in the history
We have decided that there is one meaning of “identifier”, that it is “formula identifier”, that it is what “identify” returns, and that we can consequently consistently abbreviate it as “Id” or “id”.

While we’re here, abbreviate `provideControllerForFormulaIdentifier` to `provideController`.
  • Loading branch information
rekmarks authored Mar 18, 2024
2 parents 2da8c6a + eb305bb commit eca2b3a
Show file tree
Hide file tree
Showing 12 changed files with 667 additions and 804 deletions.
40 changes: 22 additions & 18 deletions packages/daemon/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import { makePromiseKit } from '@endo/promise-kit';

export const makeContextMaker = ({
controllerForFormulaIdentifier,
provideControllerForFormulaIdentifier,
}) => {
export const makeContextMaker = ({ controllerForId, provideController }) => {
/**
* @param {string} formulaIdentifier
* @param {string} id
*/
const makeContext = formulaIdentifier => {
const makeContext = id => {
let done = false;
const { promise: cancelled, reject: rejectCancelled } =
/** @type {import('@endo/promise-kit').PromiseKit<never>} */ (
Expand All @@ -25,14 +22,18 @@ export const makeContextMaker = ({
/** @type {Array<() => void>} */
const hooks = [];

/**
* @param {Error} reason
* @param {string} [prefix]
*/
const cancel = (reason, prefix = '*') => {
if (done) return disposed;
done = true;
rejectCancelled(reason || harden(new Error('Cancelled')));

console.log(`${prefix} ${formulaIdentifier}`);
console.log(`${prefix} ${id}`);

controllerForFormulaIdentifier.delete(formulaIdentifier);
controllerForId.delete(id);
for (const dependentContext of dependents.values()) {
dependentContext.cancel(reason, ` ${prefix}`);
}
Expand All @@ -44,18 +45,21 @@ export const makeContextMaker = ({
return disposed;
};

const thatDiesIfThisDies = dependentFormulaIdentifier => {
/**
* @param {string} dependentId
*/
const thatDiesIfThisDies = dependentId => {
assert(!done);
const dependentController = provideControllerForFormulaIdentifier(
dependentFormulaIdentifier,
);
dependents.set(dependentFormulaIdentifier, dependentController.context);
const dependentController = provideController(dependentId);
dependents.set(dependentId, dependentController.context);
};

const thisDiesIfThatDies = dependencyIdentifier => {
const dependencyController =
provideControllerForFormulaIdentifier(dependencyIdentifier);
dependencyController.context.thatDiesIfThisDies(formulaIdentifier);
/**
* @param {string} dependencyId
*/
const thisDiesIfThatDies = dependencyId => {
const dependencyController = provideController(dependencyId);
dependencyController.context.thatDiesIfThisDies(id);
};

/**
Expand All @@ -67,7 +71,7 @@ export const makeContextMaker = ({
};

return {
id: formulaIdentifier,
id,
cancel,
cancelled,
disposed,
Expand Down
Loading

0 comments on commit eca2b3a

Please sign in to comment.