{
  "name": "Loop Over Items: batches with a Wait",
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Make 5 Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Make 5 Items": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Batch": {
      "main": [
        [
          {
            "node": "Wait 1s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 1s": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Summary",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Process Batch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "nodes": [
    {
      "id": "5e0b2537-04f0-4c51-ad97-da4729332e8f",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        192
      ],
      "parameters": {}
    },
    {
      "id": "a21c5635-ad07-44d9-9f79-e448764041e1",
      "name": "Make 5 Items",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        224,
        192
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "return [1,2,3,4,5].map(n => ({ json: { n } }));"
      }
    },
    {
      "id": "5d44011d-7100-4f52-b6cd-5ee79551b51f",
      "name": "Summary",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        0
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const items = $input.all();\nreturn [{ json: { doneItems: items.length, ns: items.map(i => i.json.n), hasDoubled: items.every(i => i.json.doubled !== undefined), runIndexes: items.map(i => i.json.currentRunIndex) } }];"
      }
    },
    {
      "id": "a7674ff2-17c4-42de-a5bb-df453d844260",
      "name": "Process Batch",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        672,
        192
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "language": "javaScript",
        "jsCode": "const ctx = $('Loop Over Items').context;\nreturn $input.all().map(i => ({ json: { n: i.json.n, doubled: i.json.n * 2, batchItems: $input.all().length, currentRunIndex: ctx.currentRunIndex, noItemsLeft: ctx.noItemsLeft, at: new Date().toISOString() } }));"
      }
    },
    {
      "id": "87e5f1f5-96e4-4ab5-be49-209712ac09c0",
      "name": "Wait 1s",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        896,
        272
      ],
      "parameters": {
        "resume": "timeInterval",
        "amount": 1,
        "unit": "seconds"
      }
    },
    {
      "id": "782a50c4-eb13-459f-9bb2-dd7f6e3c1329",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        448,
        192
      ],
      "parameters": {
        "batchSize": 2,
        "options": {}
      }
    }
  ],
  "settings": {
    "executionOrder": "v1"
  }
}
