Execute multiple Stripe API calls concurrently.
When to use
Batch.run/2 is designed for fan-out patterns — situations where you need
to fetch several independent Stripe resources in parallel for a single user request.
Typical example: loading a dashboard that needs a customer, their active subscriptions, and their recent invoices simultaneously:
{:ok, results} =
LatticeStripe.Batch.run(client, [
{LatticeStripe.Customer, :retrieve, ["cus_123"]},
{LatticeStripe.Subscription, :list, [%{customer: "cus_123"}]},
{LatticeStripe.Invoice, :list, [%{customer: "cus_123"}]}
])
[customer_result, subscriptions_result, invoices_result] = resultsWhat it is NOT
Batch.run/2 is not a substitute for Stripe's native batch API. Each call is
an independent HTTP request — there is no server-side batching, no atomic
transaction, and no reduced HTTP overhead. Use it when you want concurrent
fan-out in your application layer; use Stripe's batch endpoint when you need
atomic multi-resource operations.
Error isolation
Individual task failures do not crash the caller or cancel other tasks.
Each slot in the result list independently resolves to {:ok, result} or
{:error, %LatticeStripe.Error{}}.
for result <- results do
case result do
{:ok, resource} -> process(resource)
{:error, err} -> Logger.warning("Stripe call failed: #{err.message}")
end
end
Summary
Types
@type result() :: {:ok, term()} | {:error, LatticeStripe.Error.t()}
Functions
@spec run(LatticeStripe.Client.t(), [task()], keyword()) :: {:ok, [result()]} | {:error, LatticeStripe.Error.t()}