You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Map handlers only receive individual array elements. If a handler needs access to the original flow input, outputs from other dependencies, or any additional data, include that data in the array elements via a previous step.
74
+
Map handlers can access flow input via `await ctx.flowInput`, but for better performance, include needed data directly in the array elements via a previous step.
This pattern applies whenever a map handler needs any data beyond the array elements themselves. Add a step before the map that enriches the array elements with whatever data the handler needs - whether that's the original flow input, outputs from other dependencies, or both.
115
115
116
+
:::tip[Why is ctx.flowInput async?]
117
+
`ctx.flowInput` is lazy-loaded to prevent data duplication. For map steps processing thousands of items, including the full flow input in each task record would multiply storage and transfer costs. Instead, it's fetched on-demand when you `await` it. The enrichment pattern above is more efficient because it includes only the data each item actually needs.
118
+
:::
119
+
116
120
:::note[Debugging Map Tasks]
117
121
When debugging map steps, use [`context.stepTask.task_index`](/reference/context/#steptask) to identify which array element each task is processing.
// ctx.flowInput provides access to the original flow input
131
+
//await ctx.flowInput provides access to the original flow input
132
132
returnprocessItem(item);
133
133
})
134
134
```
135
135
136
136
This constraint keeps map handlers focused on transforming individual elements. If a map handler needs additional data from other step outputs, include that data in the array elements via a previous step. The context parameter provides access to flow input when needed.
137
137
138
+
:::tip[Accessing flowInput in map handlers]
139
+
While `await ctx.flowInput` works in map handlers, it's lazy-loaded and fetched separately for each task. For better performance with large arrays, enrich your array elements with the data they need before mapping. See [Enriching Array Elements](/build/process-arrays-in-parallel/#enriching-array-elements-with-additional-data) for the recommended pattern.
0 commit comments