Skip to content

Commit

Permalink
refactor(daemon): Rename soft/hard cancel to graceful/force cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
rekmarks committed Feb 14, 2024
1 parent 2a5f379 commit a29cbe8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/daemon/src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const makeContextMaker = ({
}
dependents.clear();

// Execute all cancellation hooks and resolve a single `undefined` for them.
resolveDisposed(Promise.all(hooks.map(hook => hook())).then(() => {}));

return disposed;
Expand Down
10 changes: 5 additions & 5 deletions packages/daemon/src/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const makeEndoBootstrap = async (
// TODO validate workerId512
const daemonWorkerFacet = makeWorkerBootstrap(workerId512);

const { promise: hardCancelled, reject: hardCancel } =
const { promise: forceCancelled, reject: forceCancel } =
/** @type {import('@endo/promise-kit').PromiseKit<never>} */ (
makePromiseKit()
);
Expand All @@ -146,10 +146,10 @@ const makeEndoBootstrap = async (
await controlPowers.makeWorker(
workerId512,
daemonWorkerFacet,
Promise.race([hardCancelled, gracePeriodElapsed]),
Promise.race([forceCancelled, gracePeriodElapsed]),
);

const softCancel = async () => {
const gracefulCancel = async () => {
E.sendOnly(workerDaemonFacet).terminate();
const cancelWorkerGracePeriod = () => {
throw new Error('Exited gracefully before grace period elapsed');
Expand All @@ -164,11 +164,11 @@ const makeEndoBootstrap = async (
`Worker termination grace period ${gracePeriodMs}ms elapsed`,
);
})
.catch(hardCancel);
.catch(forceCancel);
await workerTerminated;
};

context.onCancel(softCancel);
context.onCancel(gracefulCancel);

const worker = Far('EndoWorker', {});

Expand Down

0 comments on commit a29cbe8

Please sign in to comment.