Skip to content

Commit

Permalink
added: up return
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Pasynok committed Nov 3, 2024
1 parent 7a99eae commit 31992d5
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/compose/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const statusIs = {
idle: (s: ContainerStatus) => s === CONTAINER_STATUS.idle,
};

// todo: tons of tests
// todo: clearNode extra stores and variables on container fail|off|done, and on all up
const upFn = (containers: AnyContainer[]) => {
const CONTAINER_IDS = new Set<string>();

Expand All @@ -27,6 +25,23 @@ const upFn = (containers: AnyContainer[]) => {

let apis: Record<string, Awaited<ReturnType<AnyContainer['start']>>['api']> = {};

const containersStatuses = containers.reduce<Record<AnyContainer['id'], AnyContainer['$status']>>((acc, x) => {
acc[x.id] = x.$status;
return acc;
}, {});

const $result = combine(containersStatuses, (kv) => {
const statusList = Object.values(kv);
const done = statusList.every((s) => /^(done|fail|off)$/.test(s));
const hasErrors = statusList.some(statusIs.fail);

return {
done,
hasErrors,
statuses: kv,
};
});

for (const container of containers) {
const $strictDepsResolving: Store<ContainerStatus> = combine(
(container.dependsOn ?? []).map((d) => d.$status),
Expand Down Expand Up @@ -74,11 +89,20 @@ const upFn = (containers: AnyContainer[]) => {
$depsDone.watch((x) => {
if (x) enableFx();
});

// fixme: container.$status.watch(off | fail) -> clear stores (clearNode)
}

// after start
return new Promise((resolve, reject) => {
$result.watch((x) => {
if (x.done === true) {
// fixme: clear all nodes
if (x.hasErrors) {
reject(x.statuses);
}

resolve(x.statuses);
}
});
});
};

// todo: think about dynamic feature stop
Expand Down

0 comments on commit 31992d5

Please sign in to comment.