Files
start-os/sdk/package/lib/trigger/successFailure.ts
2026-02-05 08:10:53 -07:00

28 lines
1004 B
TypeScript

import { Trigger } from "."
import { lastStatus } from "./lastStatus"
/**
* Creates a trigger with different timing for success vs failure/starting states.
*
* This is a simplified wrapper around `lastStatus` for the common case
* where you want one timing during healthy operation and another during
* any error condition (failure or starting).
*
* @param o.duringSuccess - Trigger to use when the last check succeeded
* @param o.duringError - Trigger to use for failure, starting, or unknown states
* @returns A composite trigger that adapts to success/failure state
*
* @example
* ```typescript
* // Check every minute when healthy, every 5 seconds when unhealthy
* const trigger = successFailure({
* duringSuccess: cooldownTrigger(60000), // 1 minute
* duringError: cooldownTrigger(5000) // 5 seconds
* })
* ```
*/
export const successFailure = (o: {
duringSuccess: Trigger
duringError: Trigger
}) => lastStatus({ success: o.duringSuccess, default: o.duringError })