export function createStreamTerminalOutcomeTracker() {
    let settled = false;
    let resolveOutcome;
    const outcome = new Promise((resolve) => {
        resolveOutcome = resolve;
    });
    const settle = (value) => {
        if (settled) {
            return;
        }
        settled = true;
        resolveOutcome(value);
    };
    return {
        outcome,
        complete: () => settle({ kind: "completed" }),
        fail: (message) => settle({ kind: "upstream_error", message }),
        cancel: () => settle({ kind: "client_cancelled" }),
    };
}
export function mergeStreamTerminalOutcome(outcome, sseErrorMessage) {
    if (outcome.kind === "completed" && sseErrorMessage) {
        return { kind: "upstream_error", message: sseErrorMessage };
    }
    return outcome;
}
//# sourceMappingURL=streamOutcome.js.map