> [!NOTE]
> This README was generated by [SKILL](https://github.com/agenvoy/skill-readme-generate), get the ZH version from [here](https://github.com/pardnchiu/go-queue/blob/develop/doc/README.zh.md).

***

<p align="center">
<strong>PRIORITY TASKS THAT NEVER STARVE!</strong>
</p>

<p align="center">
<a href="https://pkg.go.dev/github.com/pardnchiu/go-queue"><img src="https://img.shields.io/badge/GO-REFERENCE-blue?include_prereleases&style=for-the-badge" alt="Go Reference"></a>
<a href="https://github.com/pardnchiu/go-queue/releases"><img src="https://img.shields.io/github/v/tag/pardnchiu/go-queue?include_prereleases&style=for-the-badge" alt="Release"></a>
<a href="https://github.com/pardnchiu/go-queue/blob/develop/LICENSE"><img src="https://img.shields.io/github/license/pardnchiu/go-queue?include_prereleases&style=for-the-badge" alt="License"></a>
</p>

***

> A Go priority task queue with a bounded worker pool, anti-starvation promotion, and retries with per-task timeouts

## Table of Contents

- [Features](#features)
- [Architecture](#architecture)
- [License](#license)
- [Author](#author)

## Features

> `go get github.com/pardnchiu/go-queue` · [Documentation](https://github.com/pardnchiu/go-queue/blob/develop/doc/doc.md)

- **Five-Level Priority Heap** — Immediate, High, Retry, Normal, and Low share one min-heap, with FIFO ordering inside each level.
- **Anti-Starvation Promotion** — Low and Normal tasks promote automatically after a wait threshold, so bursts of high-priority work never starve them.
- **Preset-Driven Timeouts** — Named presets bind a priority and a base timeout, and the effective timeout scales by priority within a 15–120 second window.
- **Retry and Panic Isolation** — Failed tasks re-enter at a dedicated Retry priority, and panics become errors instead of killing the worker pool.
- **Atomic Lifecycle** — CAS drives the Created → Running → Closed transitions, and `Shutdown` drains remaining tasks under a caller-supplied deadline.

## Architecture

> [Full Architecture](https://github.com/pardnchiu/go-queue/blob/develop/doc/architecture.md)

```mermaid
graph TB
    C[Caller] -->|Enqueue| P[Pending Queue]
    P --> H[Priority Min-Heap]
    H -->|Pop + Promote| W[Worker Pool]
    W --> E[Execute + Timeout + Panic Recovery]
    E -->|Failed and retryable| P
    E -->|Success| CB[Callback]
    E --> L[slog Events]
    S[Atomic State] -.-> P
```

## License

This project is licensed under the [MIT LICENSE](https://github.com/pardnchiu/go-queue/blob/develop/LICENSE).

## Author

Just [open an issue](https://github.com/pardnchiu/go-queue/issues/new) to share an idea.

<a href="https://github.com/pardnchiu/go-queue/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=pardnchiu/go-queue&cache_bust=2026-10-07" alt="go-queue contributors" />
</a>

***

©️ 2025 [邱敬幃 Pardn Chiu](https://www.linkedin.com/in/pardnchiu)
