Files
start-os/sdk/lib/trigger/successFailure.ts
2024-03-28 10:40:47 -06:00

33 lines
823 B
TypeScript

import { Trigger } from "."
export function successFailure(o: {
duringSuccess: Trigger
duringError: Trigger
}): Trigger {
return async function* (getInput) {
while (true) {
const beforeSuccess = o.duringSuccess(getInput)
yield
let currentValue = getInput()
beforeSuccess.next()
for (
let res = await beforeSuccess.next();
currentValue?.lastResult !== "success" && !res.done;
res = await beforeSuccess.next()
) {
yield
currentValue = getInput()
}
const duringError = o.duringError(getInput)
for (
let res = await duringError.next();
currentValue?.lastResult === "success" && !res.done;
res = await duringError.next()
) {
yield
currentValue = getInput()
}
}
}
}