Vercel Logo
DOCS
DEVELOPER GUIDELINE
LOOPS

Looping Pipeline

The Looping Pipeline in Syncraft serves as a looping mechanism akin to the programmatic "While" loops familiar to developers. This pipeline continually executes a specified logic until a defined break condition is met. It's an indispensable tool for scenarios necessitating repeated logic execution until certain conditions are satisfied, be it awaiting a status change in a database or processing large data chunks. Let's unravel the workings of the Looping Pipeline through a demonstrative example.

Core Components:

  1. Break Condition: The condition under which the loop will cease execution.
  2. Loop Body: The crux of logic to be iterated.
  3. Timebox: The parameter used to specify the maximum duration for the loop to run.
[ { "query": { "id": { "eq": 2 } }, "selection": { "id": true, "name": true }, "root": "Users" }, { "while": { "active": { "eq": false } }, "do": { "query": { "id": { "eq": 1 } }, "selection": { "id": true, "name": true, "active": true }, "root": "Users" }, "timebox": 5000 } ]

Workflow:

  1. Condition Evaluation: The while block houses the break condition. In this example, the loop will continue as long as the active field is false.
  2. Loop Execution: The do block contains the logic to be executed in each iteration. Here, it queries for a user with id equal to 1 from the Users root, selecting the id, name, and active fields.
  3. Timeboxing: The timebox parameter (expressed in milliseconds) is a safeguard to ensure the loop doesn't run indefinitely, terminating the loop if the specified duration is exceeded. Here, the loop will terminate if it runs longer than 5000 milliseconds (5 seconds), irrespective of the break condition.

By encapsulating looping logic within the query pipeline, Synccraft ensures a structured, readable, and manageable way to handle iterative logic. This encapsulation also enhances data logic isolation from the caller, making the Looping Pipeline a powerful construct for handling iterative data processing tasks.

Continue Your Journey
Conditional Branching
Continue Your Journey
Building Serial Pipelines