bedelightful/async-event

Async event

Installs: 0

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/bedelightful/async-event

v0.1 2026-01-14 02:46 UTC

This package is auto-updated.

Last update: 2026-01-14 18:08:30 UTC


README

  • Events will be placed into a coroutine and then executed in sequence
  • Core code is \BeDelightful\AsyncEvent\AsyncEventDispatcher::dispatch

Installation

  • Install
composer require bedelightful/async-event
  • Publish configuration
php bin/hyperf.php vendor:publish bedelightful/async-event
  • Run database migration
php bin/hyperf.php migrate

Usage

  • To avoid affecting existing logic, use the new dispatcher

demo

<?php

declare(strict_types=1);
/**
 * Copyright (c) Be Delightful , Distributed under the MIT software license
 */
 
namespace App\Controller;

use App\Event\DemoEvent;
use Hyperf\Di\Annotation\Inject;
use BeDelightful\AsyncEvent\AsyncEventDispatcher;

class IndexController extends AbstractController
{
    /**
     * @Inject()
     */
    protected AsyncEventDispatcher $asyncEventDispatcher;

    public function index()
    {
        $user = $this->request->input('user', 'Hyperf');
        $method = $this->request->getMethod();

        $this->asyncEventDispatcher->dispatch(new DemoEvent([123,222], 9));

        return [
            'method' => $method,
            'message' => "Hello {$user}.",
        ];
    }
}
  • When the maximum execution count is reached, you can send message notifications, but you need to add configuration yourself. This project only provides the maximum retry event

Notes

  • Try to avoid using coroutine context to pass data in events, as events are asynchronous and may cause data inconsistency