orderfunctionfunction order<N extends string>(graph: Graph<N>): Result<readonly N[], Cycle<N>>The nodes in an order where each comes after every node it needs; ties broken by name, so the order is the same every time. Or the first cycle found.
Graphs of work: an order in which each node comes after the nodes it needs (or the cycle that makes one impossible), and a schedule that runs each node the moment the nodes it needs are done, as many at once as asked, skipping what depends on a failure and holding back nothing else (0001-core FR-005). Taken from erga's lib/ts/graph (the build graph), with nodes of any string type.
import { order } from "./graph.ts";
order(new Map([["test", ["build"]], ["build", ["fetch"]], ["fetch", []]])); // { kind: "ok", value: ["fetch", "build", "test"] }orderfunctionfunction order<N extends string>(graph: Graph<N>): Result<readonly N[], Cycle<N>>The nodes in an order where each comes after every node it needs; ties broken by name, so the order is the same every time. Or the first cycle found.
schedulefunctionfunction schedule<N extends string>(graph: Graph<N>, jobs: number, start: (n: N) => Promise<boolean>, skip?: (n: N, because: N) => void): Promise<ReadonlyMap<N, Ran>>Every node of an acyclic graph run, each after the nodes it needs, at most jobs at once: start runs a node and says whether it succeeded; a node whose needed node failed or was skipped is skipped, and skip is told which node it waited for. How each node ended. A cycle, or a start that rejects, rejects the schedule.
Cycletypeno test imports ittype Cycle<N extends string> = { readonly kind: "cycle"; readonly nodes: readonly N[] };A cycle among nodes: the nodes in it, in order, the first repeated at the end.
Graphtypetype Graph<N extends string> = ReadonlyMap<N, readonly N[]>;A graph: each node and the nodes it needs. A needed node that is not a key of the graph is outside it, and ignored.
Rantypeno test imports ittype Ran = "done" | "failed" | "skipped";How one node of a scheduled run ended.