mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add documentation for verifyRunnablesAreDAG
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
d12f59a6a4
commit
1fc31d39ca
@ -2,7 +2,7 @@
|
|||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import type { DiContainerForInjection, Injectable, InjectionInstanceWithMeta, InjectionToken } from "@ogre-tools/injectable";
|
import type { DiContainerForInjection, Injectable, InjectionInstanceWithMeta } from "@ogre-tools/injectable";
|
||||||
import { getOrInsertSetFor, isDefined } from "../utils";
|
import { getOrInsertSetFor, isDefined } from "../utils";
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
@ -23,10 +23,16 @@ const computedNextEdge = (traversed: string[], graph: Map<string, Set<string>>,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export function verifyRunnablesAreDAG<Param>(injectionToken: InjectionToken<Runnable<Param>, void>, runnables: RunnableWithId<Param>[]): void;
|
/**
|
||||||
export function verifyRunnablesAreDAG<Param>(injectionToken: InjectionToken<RunnableSync<Param>, void>, runnables: RunnableSyncWithId<Param>[]): void;
|
* Verifies that the graph produces by `runnables`'s `runAfter`'s is acyclic. Namely that it
|
||||||
|
* produces a Directed Acyclic Graph.
|
||||||
|
* @param tokenId The ID of the injectionToken that was `injectManyWithMeta()`-ed. Used for error messages
|
||||||
|
* @param runnables The list of runnables to check.
|
||||||
|
*/
|
||||||
|
export function verifyRunnablesAreDAG<Param>(tokenId: string, runnables: RunnableWithId<Param>[]): void;
|
||||||
|
export function verifyRunnablesAreDAG<Param>(tokenId: string, runnables: RunnableSyncWithId<Param>[]): void;
|
||||||
|
|
||||||
export function verifyRunnablesAreDAG<Param>(injectionToken: InjectionToken<Runnable<Param>, void> | InjectionToken<RunnableSync<Param>, void>, runnables: (RunnableWithId<Param>[]) | (RunnableSyncWithId<Param>[])): void {
|
export function verifyRunnablesAreDAG<Param>(tokenId: string, runnables: (RunnableWithId<Param>[]) | (RunnableSyncWithId<Param>[])): void {
|
||||||
const rootId = uuid.v4();
|
const rootId = uuid.v4();
|
||||||
const runnableGraph = new Map<string, Set<string>>();
|
const runnableGraph = new Map<string, Set<string>>();
|
||||||
const seenIds = new Set<string>();
|
const seenIds = new Set<string>();
|
||||||
@ -55,7 +61,7 @@ export function verifyRunnablesAreDAG<Param>(injectionToken: InjectionToken<Runn
|
|||||||
const runnable = runnables.find(runnable => runnable.id === id);
|
const runnable = runnables.find(runnable => runnable.id === id);
|
||||||
|
|
||||||
if (!runnable) {
|
if (!runnable) {
|
||||||
throw new Error(`Runnable "${id}" is not part of the injection token "${injectionToken.id}"`);
|
throw new Error(`Runnable "${id}" is not part of the injection token "${tokenId}"`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const runAfters = [runnable.runAfter]
|
const runAfters = [runnable.runAfter]
|
||||||
@ -64,7 +70,7 @@ export function verifyRunnablesAreDAG<Param>(injectionToken: InjectionToken<Runn
|
|||||||
.map(runnable => runnable.id)
|
.map(runnable => runnable.id)
|
||||||
.join('", "');
|
.join('", "');
|
||||||
|
|
||||||
throw new Error(`Runnable "${id}" is unreachable for injection token "${injectionToken.id}": run afters "${runAfters}" are a part of different injection tokens.`);
|
throw new Error(`Runnable "${id}" is unreachable for injection token "${tokenId}": run afters "${runAfters}" are a part of different injection tokens.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export function runManyFor(di: DiContainerForInjection): RunMany {
|
|||||||
const executeRunnable = executeRunnableWith(param);
|
const executeRunnable = executeRunnableWith(param);
|
||||||
const allRunnables = di.injectManyWithMeta(injectionToken).map(x => convertToWithId(x));
|
const allRunnables = di.injectManyWithMeta(injectionToken).map(x => convertToWithId(x));
|
||||||
|
|
||||||
verifyRunnablesAreDAG(injectionToken, allRunnables);
|
verifyRunnablesAreDAG(injectionToken.id, allRunnables);
|
||||||
|
|
||||||
await Promise.all(allRunnables.map(executeRunnable));
|
await Promise.all(allRunnables.map(executeRunnable));
|
||||||
};
|
};
|
||||||
|
|||||||
@ -68,7 +68,7 @@ export function runManySyncFor(di: DiContainerForInjection): RunManySync {
|
|||||||
const executeRunnable = executeRunnableWith(param);
|
const executeRunnable = executeRunnableWith(param);
|
||||||
const allRunnables = di.injectManyWithMeta(injectionToken).map(convertToWithId);
|
const allRunnables = di.injectManyWithMeta(injectionToken).map(convertToWithId);
|
||||||
|
|
||||||
verifyRunnablesAreDAG(injectionToken, allRunnables);
|
verifyRunnablesAreDAG(injectionToken.id, allRunnables);
|
||||||
|
|
||||||
allRunnables.forEach(executeRunnable);
|
allRunnables.forEach(executeRunnable);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user