API ReferenceFunctions
createSharedThrottle
Function: createSharedThrottle()
function createSharedThrottle(config: ThrottleConfig): ThrottleGate;Defined in: transport/throttle.ts:261
Build a SHARED ThrottleGate for use across multiple
SnapcapClient instances in the same process.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | ThrottleConfig | The throttle config (rules) to enforce across all clients that share the returned gate. |
Returns
A ThrottleGate that can be passed into every
SnapcapClient's throttle constructor option.
Remarks
Pass the returned gate as throttle: gate into each client's constructor
— all clients will await the same internal state, so the aggregate request
rate respects the configured rules regardless of how many clients are
coordinating.
This is the multi-tenant anti-spam pattern. The in-process multi-instance architecture makes it possible — process-per-instance deployments would require external coordination (file locks, network coordinator, shared memory) which is genuine pain.
Example
const gate = createSharedThrottle({ rules: RECOMMENDED_THROTTLE_RULES });
const clients = tenants.map(t => new SnapcapClient({
dataStore: t.store, username: t.name, password: t.pw,
throttle: gate,
}));