mintWithRateLimit first checks canMintCouponsNow. If rate limited, it awaits waitUntilCanMint with the same options (plus optional onBeforeMint), then invokes mintFn.
Example
const { result, wasRateLimited, waitedMs } = await ocp.CouponMinter.mintWithRateLimit(
COUPON_MINTER_PAYLOAD,
async () => {
return canton.ledger.submitAndWaitForTransactionTree({ commands: [mintCmd] });
},
{ maxWaitMs: 60_000, onBeforeMint: () => console.log('Minting…') }
);
Parameters
payload(required) —CouponMinterPayload.mintFn(required) —() => Promise<T>executed after any wait.options(optional) — extendsWaitUntilCanMintOptionswithonBeforeMint?: () => void.
Returns
MintWithRateLimitResult<T> — { wasRateLimited, waitedMs, result }.
Errors
WaitAbortedError,WaitTimeoutError,OcpValidationError— same as wait path.- Any error thrown by
mintFnpropagates unchanged.
See also
Source
src/functions/CouponMinter/waitUntilCanMint.ts(mintWithRateLimit)