Skip to content

Reference

CouponMinter.mintWithRateLimit

Optionally waits via waitUntilCanMint, then runs your async mintFn and returns result with wasRateLimited and waitedMs metadata.

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) — extends WaitUntilCanMintOptions with onBeforeMint?: () => void.

Returns

MintWithRateLimitResult<T>{ wasRateLimited, waitedMs, result }.

Errors

  • WaitAbortedError, WaitTimeoutError, OcpValidationError — same as wait path.
  • Any error thrown by mintFn propagates unchanged.

See also

Source