flattenInstructionPlan

function flattenInstructionPlan(instructionPlan): (
    | Readonly<{
          getMessagePacker: () => MessagePacker;
          kind: 'messagePacker';
          planType: 'instructionPlan';
      }>
    | Readonly<{
          instruction: Instruction;
          kind: 'single';
          planType: 'instructionPlan';
      }>
)[];

Retrieves all individual SingleInstructionPlan and MessagePackerInstructionPlan instances from an instruction plan tree.

This function recursively traverses any nested structure of instruction plans and extracts all the leaf plans they contain. It's useful when you need to access all the individual instructions or message packers that will be executed, regardless of their organization in the plan tree (parallel or sequential).

Parameters

ParameterTypeDescription
instructionPlanInstructionPlanThe instruction plan to extract leaf plans from

Returns

( | Readonly<{ getMessagePacker: () => MessagePacker; kind: "messagePacker"; planType: "instructionPlan"; }> | Readonly<{ instruction: Instruction; kind: "single"; planType: "instructionPlan"; }>)[]

An array of all single and message packer instruction plans contained in the tree

Example

const plan = parallelInstructionPlan([
  sequentialInstructionPlan([instructionA, instructionB]),
  nonDivisibleSequentialInstructionPlan([instructionC, instructionD]),
  instructionE,
]);
 
const leafPlans = flattenInstructionPlan(plan);
// Array of `SingleInstructionPlan` containing:
// instructionA, instructionB, instructionC, instructionD and instructionE.

See

On this page