createTransactionPlanExecutorWithConcurrentLeaves

function createTransactionPlanExecutorWithConcurrentLeaves<TContext>(
    config,
): TransactionPlanExecutor<TContext>;

Creates a transaction plan executor that processes every leaf concurrently.

It takes the same configuration as createTransactionPlanExecutor and its executeTransactionMessage callback follows the same contract: it receives a fresh mutable context object for every leaf and returns the complete TContext a successful result must carry. On success the two are merged with the returned value taking precedence; on a throw the context accumulated so far is preserved in the failed result.

The difference is the traversal. This executor preserves the input plan's nesting, order, and divisibility in the returned result, but it does not enforce the execution dependencies expressed by sequential plans: every leaf callback is started immediately, without a concurrency limit. This makes it suitable for operations such as signing or serializing transactions that can be performed independently. For the same reason, a callback that throws does not cancel the other leaves — each one runs to completion — and non-divisible sequential plans are supported.

The optional abort signal is forwarded to every leaf callback and enforced by the executor. When the signal is already aborted, leaves are canceled without invoking their callbacks. When it is aborted during execution, the executor stops waiting for active callbacks and records failed results carrying the abort reason and the context accumulated so far — a value the callback resolves with afterwards is discarded.

After all leaves settle, a plan containing failed or canceled results throws a failed execution error containing the complete result tree.

Type Parameters

Type ParameterDefault typeDescription
TContext extends TransactionPlanResultContextTransactionPlanResultContextWithSignatureThe context carried by each single transaction plan result.

Parameters

ParameterTypeDescription
configTransactionPlanExecutorConfig<TContext>Configuration object containing the transaction message executor function.

Returns

TransactionPlanExecutor<TContext>

A TransactionPlanExecutor that processes all transaction plan leaves concurrently.

Throws

SOLANA_ERROR__INSTRUCTION_PLANS__FAILED_TO_EXECUTE_TRANSACTION_PLAN if any leaf callback throws, any leaf is canceled, or the abort signal fires. The error context contains a transactionPlanResult property with the complete result tree.

Throws

SOLANA_ERROR__INVARIANT_VIOLATION__INVALID_TRANSACTION_PLAN_KIND if the plan has an unknown kind.

Example

Signing every transaction in a plan concurrently.

const executor = createTransactionPlanExecutorWithConcurrentLeaves<{ transaction: Transaction }>({
    executeTransactionMessage: async (_context, message) => {
        const transaction = await signTransactionMessageWithSigners(message);
        return { transaction };
    },
});
const result = await executor(transactionPlan);

See

On this page