承接 globus-studio/async 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

globus-studio/async

Composer 安装命令:

composer require globus-studio/async

包简介

Promise-style asynchronous programming for PHP, built on Revolt fibers and the event loop.

README 文档

README

CI License: MIT PHP Version

Promise-style asynchronous programming for PHP, built on top of Revolt fibers and the event loop. Concurrency without pthreads, without pcntl_fork, and without blocking sleep().

Features

  • async / await semantics on top of native PHP fibers.
  • Non-blocking delay() powered by Revolt's event loop.
  • Promise combinators: Async::all(), Async::race(), Async::any().
  • Timeouts via timeout() that schedules a real loop timer.
  • Cooperative cancellation with a dedicated CancelledException.
  • Event hooks: then, catch, finally, progress, plus arbitrary custom events through on().
  • Priority queue via AsyncManager for batched work.
  • PSR-4, strict types, fully tested with PHPUnit.

Requirements

Installation

composer require globus-studio/async

Quick start

<?php

require __DIR__ . '/vendor/autoload.php';

use GlobusStudio\Async\Async;
use function GlobusStudio\Async\{async, await, delay};

$task = async(function (Async $self): string {
    $self->progress(50);
    delay(0.5);          // non-blocking sleep
    $self->progress(100);
    return 'done';
});

$task->onProgress(fn ($pct) => printf("progress: %d%%\n", $pct));

echo await($task), PHP_EOL;

Concurrency

use GlobusStudio\Async\Async;
use function GlobusStudio\Async\delay;

$results = Async::all([
    'a' => Async::run(function () { delay(0.5); return 'A'; }),
    'b' => Async::run(function () { delay(0.5); return 'B'; }),
    'c' => Async::run(function () { delay(0.5); return 'C'; }),
]);
// All three finish in ~0.5s, not 1.5s.

race() returns the first settled task and cancels the rest. any() returns the first fulfilled task, throwing only if every task rejects.

Timeouts and cancellation

$slow = new Async(function () {
    delay(10);
    return 'never';
});

try {
    $slow->timeout(0.25)->await();
} catch (\GlobusStudio\Async\Exception\TimeoutException $e) {
    // Operation timed out after 0.250s.
}

Cancellation is cooperative. Calling cancel() rejects the task with CancelledException and emits a cancel event, but does not forcibly abort the underlying fiber. User code should observe cancellation at suspension points.

Error handling

Async::run(function () {
    throw new RuntimeException('nope');
})
->catch(fn (\Throwable $e) => error_log($e->getMessage()))
->finally(fn () => print "cleanup\n");

Listeners attached after a task settles are still invoked (asynchronously, on the next loop tick) so that ordering does not matter.

Priority queue

use GlobusStudio\Async\AsyncManager;

(new Async($high))->setPriority(10);
(new Async($low))->setPriority(1);

$results = AsyncManager::run(); // high-priority task starts first

API reference

Async

Method Description
__construct(callable $cb) Create a task. $cb receives the Async instance.
static run(callable $cb): self Create and immediately start.
start(): self Schedule the task on the event loop. Idempotent.
await(): mixed Suspend until settled; rethrows on rejection.
then(callable $ok, ?callable $err = null): self
catch(callable $err): self
finally(callable $cb): self
on(string $event, callable $l): self Generic event subscription.
onProgress(callable $cb): self / progress(mixed $data) Progress channel.
timeout(float $seconds): self Reject with TimeoutException if not settled in time.
cancel(): void Reject with CancelledException.
getState(): string / isPending(): bool / isSettled(): bool State inspection.
setPriority(int $p): self Enqueue in AsyncManager.
static all(array $tasks): array Concurrent join, preserves keys.
static race(array $tasks): mixed First to settle wins.
static any(array $tasks): mixed First to fulfill wins.

AsyncManager

Method Description
static addTask(Async $t, int $priority = 0): void
static run(): array Drain the queue, returning per-task results (or Throwable on failure).
static runTasks(): void Alias of run() for backwards compatibility.
static cancelAllOtherTasks(Async $keep): void
static clear(): void / count(): int

Helpers (GlobusStudio\Async namespace)

  • async(callable $cb): Async
  • await(Async $task): mixed
  • delay(float $seconds): void

Running the test suite

composer install
composer test

The suite covers fulfillment, rejection, timeouts, cancellation, concurrency guarantees of all/race/any, listener ordering, and AsyncManager prioritisation.

License

MIT. See LICENSE.

globus-studio/async 适用场景与选型建议

globus-studio/async 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27 次下载、GitHub Stars 达 22, 最近一次更新时间为 2026 年 04 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「event-loop」 「async」 「concurrency」 「promise」 「await」 「fiber」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 globus-studio/async 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 globus-studio/async 我们能提供哪些服务?
定制开发 / 二次开发

基于 globus-studio/async 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 27
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 48
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 16
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-25