mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-30 12:21:57 +00:00
chore: Adding mainFn helpers
This commit is contained in:
28
lib/health/trigger/changeOnFirstSuccess.ts
Normal file
28
lib/health/trigger/changeOnFirstSuccess.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { TriggerInput } from "./TriggerInput";
|
||||
import { Trigger } from "./index";
|
||||
|
||||
export function changeOnFirstSuccess(o: {
|
||||
beforeFirstSuccess: Trigger;
|
||||
afterFirstSuccess: Trigger;
|
||||
}) {
|
||||
return async function* () {
|
||||
const beforeFirstSuccess = o.beforeFirstSuccess();
|
||||
let currentValue: TriggerInput = yield;
|
||||
beforeFirstSuccess.next(currentValue);
|
||||
for (
|
||||
let res = await beforeFirstSuccess.next(currentValue);
|
||||
currentValue?.lastResult !== "success" && !res.done;
|
||||
res = await beforeFirstSuccess.next(currentValue)
|
||||
) {
|
||||
currentValue = yield;
|
||||
}
|
||||
const afterFirstSuccess = o.afterFirstSuccess();
|
||||
for (
|
||||
let res = await afterFirstSuccess.next(currentValue);
|
||||
!res.done;
|
||||
res = await afterFirstSuccess.next(currentValue)
|
||||
) {
|
||||
currentValue = yield;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user