Documentation Index
Fetch the complete documentation index at: https://mintlify.com/visible/cruel/llms.txt
Use this file to discover all available pages before exploring further.
Function Signature
function withHedge<T extends AnyFn>(
fn: T,
options: HedgeOptions
): T
Wraps a function with hedging strategy. Sends multiple parallel requests with delays and returns the first successful response.
Options
Number of hedged requests to send.
Delay in milliseconds between sending each hedged request.
Return Type
Returns the wrapped function that sends multiple hedged requests.
Types
interface HedgeOptions {
count: number
delay: number
}
Example
import { withHedge } from 'cruel'
const hedgedFetch = withHedge(
async (url: string) => {
const response = await fetch(url)
if (!response.ok) throw new Error('Request failed')
return response.json()
},
{
count: 3,
delay: 100
}
)
// Sends 3 requests:
// - First request sent immediately
// - Second request sent after 100ms
// - Third request sent after 200ms
// Returns the first successful response
const data = await hedgedFetch('https://api.example.com/data')