Throttle
Space requests by rate and cap concurrency, scoped per stitch or per host.
Add throttle to a stitch when you need to stay under an API's rate limit and
keep in-flight requests bounded — it spaces calls to a target rate and caps how
many run at once, before any request leaves.
Example
import { } from 'stitchapi';
const = ({
: 'https://api.example.com',
: '/search',
: { : '5/s', : 2, : 'host' },
});Calls to search() are spaced to five per second with at most two running
concurrently. When a call has to wait, the stitch emits a progress event with
phase throttled, so a waiting call is visible on the event stream rather than
silently stalled.
Options
rate is a string like "5/s" — a minimum spacing between successive calls,
not a token bucket. concurrency caps simultaneous in-flight calls; either may
be set on its own.
scope decides what shares the budget: 'stitch' (the default) gives each
stitch its own budget, while 'host' pools the budget across every stitch
hitting the same host — use it when one API publishes a single account-wide
limit. Throttle state lives in the stitch store, so giving stitches a shared
store turns a single-process budget into a
distributed one that spans workers.
A throttled wait surfaces as a throttled progress phase on the event
stream — see The event stream.
See Reference → Config types for every field.