# zaidsasa/workerpool architecture

> Architecture diagram of the GitHub repository zaidsasa/workerpool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zaidsasa/workerpool
- Repository: https://github.com/zaidsasa/workerpool

## Overview

This is a small Go concurrency-limiting worker-pool library. Callers configure and create a pool, submit tasks, then wait for completion or context cancellation; the pool dispatches workers up to its semaphore limit. The graph reflects the sampled runtime source; it does not include tests or benchmark machinery.

Main entry points: [`workerpool.go`](https://github.com/zaidsasa/workerpool/blob/main/workerpool.go) (Worker Pool), [`worker.go`](https://github.com/zaidsasa/workerpool/blob/main/worker.go) (Worker), [`semaphore.go`](https://github.com/zaidsasa/workerpool/blob/main/semaphore.go) (Semaphore), [`options.go`](https://github.com/zaidsasa/workerpool/blob/main/options.go) (Pool Options)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Pool API"]
  node_pool["Worker Pool<br/>[workerpool.go]"]
  node_options["Pool Options<br/>[options.go]"]
end

subgraph group_execution["Task Execution"]
  node_dispatcher["Dispatcher<br/>[workerpool.go]"]
  node_worker["Worker<br/>[worker.go]"]
  node_tasks["Task Queue<br/>[workerpool.go]"]
end

subgraph group_limits["Concurrency Control"]
  node_semaphore["Semaphore<br/>[semaphore.go]"]
end

node_caller(("Caller"))

node_caller -->|"creates, submits, waits"| node_pool
node_pool -->|"parses options"| node_options
node_pool -->|"creates limit"| node_semaphore
node_pool -->|"starts"| node_dispatcher
node_pool -->|"queues tasks"| node_tasks
node_dispatcher -->|"acquires capacity"| node_semaphore
node_dispatcher -->|"starts workers"| node_worker
node_worker -->|"receives tasks"| node_tasks
node_worker -->|"releases capacity"| node_semaphore
node_pool -->|"waits for completion"| node_worker
node_pool -->|"closes queue"| node_tasks
node_dispatcher -->|"closes on stop"| node_semaphore
node_worker -->|"signals task done"| node_pool

click node_pool "https://github.com/zaidsasa/workerpool/blob/main/workerpool.go"
click node_options "https://github.com/zaidsasa/workerpool/blob/main/options.go"
click node_dispatcher "https://github.com/zaidsasa/workerpool/blob/main/workerpool.go"
click node_worker "https://github.com/zaidsasa/workerpool/blob/main/worker.go"
click node_tasks "https://github.com/zaidsasa/workerpool/blob/main/workerpool.go"
click node_semaphore "https://github.com/zaidsasa/workerpool/blob/main/semaphore.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pool,node_options toneBlue
class node_dispatcher,node_worker,node_tasks toneAmber
class node_semaphore toneMint
class node_caller toneIndigo
```

## Components

### Pool API

- [Worker Pool](https://github.com/zaidsasa/workerpool/blob/main/workerpool.go): `workerpool.go`
- [Pool Options](https://github.com/zaidsasa/workerpool/blob/main/options.go): `options.go`

### Task Execution

- [Dispatcher](https://github.com/zaidsasa/workerpool/blob/main/workerpool.go): `workerpool.go`
- [Worker](https://github.com/zaidsasa/workerpool/blob/main/worker.go): `worker.go`
- [Task Queue](https://github.com/zaidsasa/workerpool/blob/main/workerpool.go): `workerpool.go`

### Concurrency Control

- [Semaphore](https://github.com/zaidsasa/workerpool/blob/main/semaphore.go): `semaphore.go`

### Other components

- **Caller**

## Connections

- Caller → Worker Pool: creates, submits, waits
- Worker Pool → Pool Options: parses options
- Worker Pool → Semaphore: creates limit
- Worker Pool → Dispatcher: starts
- Worker Pool → Task Queue: queues tasks
- Dispatcher → Semaphore: acquires capacity
- Dispatcher → Worker: starts workers
- Worker → Task Queue: receives tasks
- Worker → Semaphore: releases capacity
- Worker Pool → Worker: waits for completion
- Worker Pool → Task Queue: closes queue
- Dispatcher → Semaphore: closes on stop
- Worker → Worker Pool: signals task done
