PHPackages                             friendsofhyperf/async-queue-closure-job - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. friendsofhyperf/async-queue-closure-job

AbandonedArchivedLibrary[Queues &amp; Workers](/categories/queues)

friendsofhyperf/async-queue-closure-job
=======================================

The async queue closure job component for Hyperf.

v3.1.4(7mo ago)0935↓73.5%1MITPHP

Since Nov 12Pushed 7mo agoCompare

[ Source](https://github.com/friendsofhyperf/async-queue-closure-job)[ Packagist](https://packagist.org/packages/friendsofhyperf/async-queue-closure-job)[ Fund](https://hdj.me/sponsors/)[ GitHub Sponsors](https://github.com/huangdijia)[ RSS](/packages/friendsofhyperf-async-queue-closure-job/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (1)Versions (6)Used By (1)

Async Queue Closure Job
=======================

[](#async-queue-closure-job)

[![Latest Stable Version](https://camo.githubusercontent.com/217f7fad6f83c8f919b68ca2d633157413940a1cbfe82bcf36dca38337a2aa0f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667269656e64736f666879706572662f6173796e632d71756575652d636c6f737572652d6a6f62)](https://packagist.org/packages/friendsofhyperf/async-queue-closure-job)[![Total Downloads](https://camo.githubusercontent.com/5c92ffe34480894bdc8f222d4e9437e5377ea34aa4fe8ce36faea71bb5f3d030/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667269656e64736f666879706572662f6173796e632d71756575652d636c6f737572652d6a6f62)](https://packagist.org/packages/friendsofhyperf/async-queue-closure-job)[![License](https://camo.githubusercontent.com/0d5cc8d59b118e585f436bfcf4b79e68ba9e3712b4f1daef87f7e3b8f6efd76c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f667269656e64736f666879706572662f6173796e632d71756575652d636c6f737572652d6a6f62)](https://github.com/friendsofhyperf/async-queue-closure-job)

The async queue closure job component for Hyperf. Execute closures as background jobs with full support for dependency injection, fluent configuration.

> **Note**: Starting from v3.1.73, this package serves as a convenience wrapper around the `friendsofhyperf/support` package. The core implementation (`CallQueuedClosure` and related classes) has been moved to the support package to eliminate circular dependencies and improve package architecture.

Installation
------------

[](#installation)

```
composer require friendsofhyperf/async-queue-closure-job
```

Basic Usage
-----------

[](#basic-usage)

```
use function FriendsOfHyperf\AsyncQueueClosureJob\dispatch;

// Simple closure dispatch
dispatch(function () {
    // Your job logic here
    var_dump('Hello from closure job!');
});

// With max attempts (retry limit)
dispatch(function () {
    // Your job logic here
})->setMaxAttempts(3);
```

Advanced Usage
--------------

[](#advanced-usage)

### Fluent API Configuration

[](#fluent-api-configuration)

```
use function FriendsOfHyperf\AsyncQueueClosureJob\dispatch;

// Chain multiple configurations
dispatch(function () {
    // Your job logic here
})
    ->onConnection('high-priority')
    ->delay(60) // Execute after 60 seconds
    ->setMaxAttempts(5);
```

### Conditional Execution

[](#conditional-execution)

```
use function FriendsOfHyperf\AsyncQueueClosureJob\dispatch;

$condition = true;

// Execute only when condition is true
dispatch(function () {
    // Your job logic here
})
    ->when($condition, function ($dispatch) {
        $dispatch->onConnection('conditional-connection');
    });

// Execute only when condition is false
dispatch(function () {
    // Your job logic here
})
    ->unless($condition, function ($dispatch) {
        $dispatch->delay(30);
    });
```

### Dependency Injection

[](#dependency-injection)

```
use function FriendsOfHyperf\AsyncQueueClosureJob\dispatch;

// Automatic dependency injection
dispatch(function (UserService $userService, LoggerInterface $logger) {
    $users = $userService->getActiveUsers();
    $logger->info('Processing ' . count($users) . ' users');
    // Process users...
});

// With custom parameters
dispatch(function (UserService $userService, int $userId) {
    $user = $userService->find($userId);
    // Process user...
})->setMaxAttempts(3);
```

API Reference
-------------

[](#api-reference)

### `dispatch(Closure $closure): PendingAsyncQueueDispatch`

[](#dispatchclosure-closure-pendingasyncqueuedispatch)

The main dispatch function that creates a closure job.

### `PendingAsyncQueueDispatch` Methods

[](#pendingasyncqueuedispatch-methods)

- `onConnection(string $connection): static` - Set the connection name
- `delay(int $delay): static` - Set execution delay in seconds
- `setMaxAttempts(int $maxAttempts): static` - Set maximum retry attempts
- `when($condition, $callback): static` - Execute callback when condition is true
- `unless($condition, $callback): static` - Execute callback when condition is false

### Supported Closure Types

[](#supported-closure-types)

- Simple closures without parameters
- Closures with dependency injection
- Closures with captured variables (`use`)
- Closures with nullable parameters

Package Architecture
--------------------

[](#package-architecture)

As of v3.1.73, this package has been refactored to improve the overall architecture:

- **Core Implementation**: Moved to `friendsofhyperf/support` package
    - `FriendsOfHyperf\Support\CallQueuedClosure`
    - `FriendsOfHyperf\Support\Traits\ClosureParameterInjection`
- **Convenience Layer**: This package now provides a namespace alias for easy migration
    - `FriendsOfHyperf\AsyncQueueClosureJob\dispatch()` → delegates to support package

### Why This Change?

[](#why-this-change)

1. **Eliminates Circular Dependencies**: The support package previously depended on this package, creating a circular dependency
2. **Single Source of Truth**: Core functionality now lives in one place
3. **Simplified Dependency Tree**: Reduces maintenance overhead
4. **Non-Breaking**: Existing code continues to work without changes

### Migration Guide

[](#migration-guide)

**No action required!** The namespace `FriendsOfHyperf\AsyncQueueClosureJob\dispatch()` continues to work as before. However, if you want to use the new location directly:

```
// Old (still supported)
use function FriendsOfHyperf\AsyncQueueClosureJob\dispatch;

// New (recommended for new code)
use function FriendsOfHyperf\Support\dispatch;
```

Testing
-------

[](#testing)

Tests for the core functionality are now maintained in the support package.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Contact
-------

[](#contact)

- [Twitter](https://twitter.com/huangdijia)
- [Gmail](mailto:huangdijia@gmail.com)

License
-------

[](#license)

[MIT](LICENSE)

---

Made with ❤️ for the Hyperf community
-------------------------------------

[](#made-with-️-for-the-hyperf-community)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance62

Regular maintenance activity

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

5

Last Release

230d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8337659?v=4)[Deeka Wong](/maintainers/huangdijia)[@huangdijia](https://github.com/huangdijia)

---

Top Contributors

[![huangdijia](https://avatars.githubusercontent.com/u/8337659?v=4)](https://github.com/huangdijia "huangdijia (6 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (2 commits)")

---

Tags

hyperfv3.1

### Embed Badge

![Health badge](/badges/friendsofhyperf-async-queue-closure-job/health.svg)

```
[![Health](https://phpackages.com/badges/friendsofhyperf-async-queue-closure-job/health.svg)](https://phpackages.com/packages/friendsofhyperf-async-queue-closure-job)
```

###  Alternatives

[hyperf/amqp

A amqplib for hyperf.

231.3M71](/packages/hyperf-amqp)[hyperf/database

A flexible database library.

192.9M319](/packages/hyperf-database)[hyperf/http-server

A HTTP Server for Hyperf.

103.0M368](/packages/hyperf-http-server)[hyperf/database-pgsql

A pgsql handler for hyperf/database.

12321.2k20](/packages/hyperf-database-pgsql)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
