0

We have created a Logic App which iterates over some elements of an array in the input json, and then appends the output of each iteration to another array.

Now, if we are doing parallel execution of the foreach loop, is there a thread safe way to create the output array from the loop?

0

1 Answer 1

0

In general, Thread safety can be attained either by applying a condition or using the same array twice for parallel processing. In Logic Apps, If the parallel processes have 2 for each loop, then you don't have to think about thread safety.

enter image description here

This takes the same array as 2 separate arrays.

enter image description here

Below is the code-view of my logic app

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "For_each": {
                "actions": {
                    "Compose": {
                        "inputs": "@items('For_each')",
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@variables('Array')",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "For_each_2": {
                "actions": {
                    "Compose_2": {
                        "inputs": "@items('For_each_2')",
                        "runAfter": {},
                        "type": "Compose"
                    }
                },
                "foreach": "@variables('Array')",
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "Array",
                            "type": "array",
                            "value": [
                                1,
                                2,
                                3,
                                4,
                                5
                            ]
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "parameters": {},
        "triggers": {
            "manual": {
                "inputs": {
                    "schema": {}
                },
                "kind": "Http",
                "type": "Request"
            }
        }
    },
    "parameters": {}
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.