PHPackages                             reinfyteam/libasync - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. reinfyteam/libasync

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

reinfyteam/libasync
===================

01PHP

Since Apr 9Pushed 2mo agoCompare

[ Source](https://github.com/ReinfyTeam/libasync)[ Packagist](https://packagist.org/packages/reinfyteam/libasync)[ RSS](/packages/reinfyteam-libasync/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

libasync
========

[](#libasync)

`libasync` is a lightweight asynchronous library designed primarily for [PocketMine-MP](https://github.com/pmmp/PocketMine-MP), but fully general-purpose. It supports **seamless multitasking**, cooperative coroutines, and even multi-thread/multi-process execution in **NTS environments** **without code changes**.

> NTS Ready LITERALLY, you can use libasync without `ext-pthread` and `ext-pmmpthread` with a true `process`, you don't need any extra work.

🚀 Pain Points Solved
--------------------

[](#-pain-points-solved)

- **Blocking Operations**: Avoid server stalls caused by synchronous I/O or heavy computation.
- **Complex Coroutine Management**: Simplifies handling of async tasks, delays, timeouts, and resource pools.
- **Thread/Process Safety**: Enables concurrent execution without rewriting logic for multi-threaded or multi-process environments.
- **Fine-grained Async Control**: Provides awaitable results, cancellation, and timing primitives like ticks and event-loop aware delays.

🤔 Why Choose This System?
-------------------------

[](#-why-choose-this-system)

- [PocketMine-MP](https://github.com/pmmp/PocketMine-MP) Optimized: Tailored to Minecraft server internals for minimal overhead.
- **Framework Agnostic**: Works in any PHP project, not limited to PocketMine-MP.
- **NTS Ready**: Transparent support for non-thread-safe PHP builds with multi-process or multi-thread fallback.
- **Flexible Event Loop**: Easily integrate with existing loops or use built-in classic event loop.
- **Lightweight &amp; Minimal**: No heavy dependencies; fully PSR-compatible design.

Features
--------

[](#features)

- **Coroutines:** Easily write asynchronous code using `async()` and `thread()`.
- **Deferred Execution:** Register deferred closures to be executed when a coroutine finishes (`defer()`).
- **Traps:** Add trap closures that trigger under specific conditions (`trap()`, `trap_online()`).
- **Timeouts:** Set timeouts for coroutine tasks (`timeout()`).
- **Coroutine Lifecycle Control:**
    - `joined()` ensures a coroutine runs to completion, even during shutdown.
    - `may_drop()` allows a coroutine to be dropped immediately if not critical.
- **Safe Closures:** Detect and prevent cyclic references in closures using `ClosureUtils::noCyclic()`.

Quick Start
-----------

[](#quick-start)

```
use function libasync\async;
use function libasync\defer;
use function libasync\delay;
use function libasync\joined;
use function libasync\may_drop;
use function libasync\thread;
use function libasync\timeout;
use function libasync\trap;

// Run an async task
async(static function() {
    // Do async work and return a value
})->panic();

async(static function() {
    // Run a task in a separate thread (or process, depending on runtime)
    $threadResult = yield from thread(static fn() => ['a' => 1, 'b' => 2]);
    // $threadResult === ['a' => 1, 'b' => 2]

    // Trap example: coroutine pauses if condition fails
    trap(static fn() => someConditionCheck());

    // Deferred cleanup: executed when coroutine finishes
    defer(static fn() => echo "Cleaning up...\n");

    // Mark a coroutine as "joined" to ensure it completes
    joined();

    // Or mark it as "may_drop" for non-critical tasks
    may_drop();

    // Set a timeout for the currently running coroutine (seconds)
    timeout(5.0); // throws if task not completed in 5s

    // Delay execution of a closure by ticks (1 tick = 50ms)
    yield from delay(static fn() => echo "Delayed hello\n", 10);

    // Player-specific trap (PocketMine-MP)
    if (class_exists(\pocketmine\player\Player::class)) {
        $player = /* get Player instance */;
        trap_online($player); // coroutine pauses if player is offline
    }
})->panic();
```

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance56

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 98.8% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/143252455?v=4)[Rodolfo Orlanda Jr.](/maintainers/rodolfoorlandajr)[@rodolfoorlandajr](https://github.com/rodolfoorlandajr)

---

Top Contributors

[![Blackjack200](https://avatars.githubusercontent.com/u/61568071?v=4)](https://github.com/Blackjack200 "Blackjack200 (161 commits)")[![rodolfoorlandajr](https://avatars.githubusercontent.com/u/143252455?v=4)](https://github.com/rodolfoorlandajr "rodolfoorlandajr (2 commits)")

### Embed Badge

![Health badge](/badges/reinfyteam-libasync/health.svg)

```
[![Health](https://phpackages.com/badges/reinfyteam-libasync/health.svg)](https://phpackages.com/packages/reinfyteam-libasync)
```

###  Alternatives

[furqansiddiqui/ethereum-php

A modern, dependency-light Ethereum library powered by a clean cryptographic core

1725.5k1](/packages/furqansiddiqui-ethereum-php)

PHPackages © 2026

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