Skip to main content

Wait Group

Synchronize parallel operations - wait for multiple concurrent tasks to complete before proceeding.

Overview

The Wait Group package provides synchronization primitives for parallel processing. Use it when you need to run multiple operations concurrently and wait for all of them to complete before continuing.

Key Features

  • Parallel Execution - Run multiple tasks concurrently
  • Synchronization - Wait for all tasks to complete
  • Counter Management - Track pending operations

Available Nodes

  • WG Create - Create a new wait group
  • WG Add - Add tasks to the wait group counter
  • WG Done - Mark a task as complete
  • WG Wait - Wait for all tasks to complete

When to Use This Package

  • Parallel Processing: Process multiple items simultaneously
  • Batch Operations: Wait for batch to complete
  • Performance: Speed up workflows with concurrency
  • Resource Optimization: Maximize throughput

How It Works

  1. Create a wait group with expected task count
  2. Start parallel tasks
  3. Each task calls Done when complete
  4. Main flow waits until all tasks are done

Typical Workflow

  1. WG Create with count of parallel tasks
  2. Start parallel processing branches
  3. WG Done in each branch when complete
  4. WG Wait to block until all done
  5. Continue with combined results

Use Cases

  • Download multiple files in parallel
  • Process multiple API calls concurrently
  • Run parallel database queries
  • Execute multiple independent operations
  • Aggregate results from parallel tasks

Notes

  • Ensure Done is called for each Add
  • WG Wait blocks until counter reaches zero
  • Use for fan-out/fan-in patterns