Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
fix: Add onDestroyHandlers to meta so that they can be invoked
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-noel committed Feb 11, 2021
1 parent 63a3449 commit 40c62fe
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions core/garment/src/garment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ export interface CacheEntry {
output: File[];
}

interface ActionMeta {
isWatchActive: boolean;
subscriptions: Set<Subscription>;
logs: LogEntry[];
inputHandler?: MetaInputHandler;
onDestroyHandler?: () => void;
outputPath?: string;
}

export type MetaInputHandler =
| { type: 'single'; fn: InputFnCallBack }
| { type: 'multi'; fn: InputFnCallBack<File[]> };
Expand Down Expand Up @@ -189,17 +198,7 @@ async function garmentFromWorkspace(
const getSnapshotId = (hash: string) => `action-${hash}`;

// The map to store an information related to each action, so it can be reused between action executions
const metaByAction = new Map<
Action,
{
isWatchActive: boolean;
subscriptions: Set<Subscription>;
logs: LogEntry[];
inputHandler?: MetaInputHandler;
onDestroyHandler?: () => void;
outputPath?: string;
}
>();
const metaByAction = new Map<Action, ActionMeta>();

let allSubscriptionsCached: Subscription[] = [];

Expand Down Expand Up @@ -1013,13 +1012,16 @@ async function garmentFromWorkspace(
{
runner: RunnerMeta;
batch: { project: Project; options: any }[];
batchMeta: ActionMeta;
}
>();
for (const action of actions) {
if (!batchesByRunner.has(action.runner.handlerPath)) {
batchesByRunner.set(action.runner.handlerPath, {
runner: action.runner,
batch: []
batch: [],
// We don't want meta per action, since longRunning should be invoked once for all projects
batchMeta: metaByAction.get(action)
});
}
const { batch } = batchesByRunner.get(action.runner.handlerPath)!;
Expand All @@ -1034,7 +1036,7 @@ async function garmentFromWorkspace(
})
});
}
for (const { runner, batch } of batchesByRunner.values()) {
for (const { runner, batch, batchMeta } of batchesByRunner.values()) {
onUpdate({ type: 'before-batch', runner, batch });

const options = {
Expand Down Expand Up @@ -1073,7 +1075,12 @@ async function garmentFromWorkspace(
dependsOnFile() {},
cacheProvider,
batch,
logger
logger,
longRunning(onDestroy) {
if (batchMeta) {
batchMeta.onDestroyHandler = onDestroy;
}
}
});

const handler = watch ? getWatcher(runner) : getHandler(runner);
Expand Down

0 comments on commit 40c62fe

Please sign in to comment.