PHPackages                             groovycarrot/event-dispatcher - 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. groovycarrot/event-dispatcher

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

groovycarrot/event-dispatcher
=============================

A HHVM asynchronous event dispatcher.

00Hack

Since Nov 19Pushed 8y ago1 watchersCompare

[ Source](https://github.com/GroovyCarrot/hhvm-event-dispatcher)[ Packagist](https://packagist.org/packages/groovycarrot/event-dispatcher)[ RSS](/packages/groovycarrot-event-dispatcher/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

HHVM asynchronous event dispatcher
==================================

[](#hhvm-asynchronous-event-dispatcher)

### Usage

[](#usage)

A simple example of adding a product to a basket: when a product is added to a basket, a couple of things need to happen; the first task is to add it to the basket itself stored in the current session. The other task is to inform the warehouse to reserve the stock, to ensure the order can be placed later on. These responsibilities should be separate in the design of an object-oriented application, which is where events come in.

```
$eventDispatcher = new Dispatcher();

// Tasks must implement the interface EventHandling.
$eventDispatcher->tasksForEvent(AddProductToBasketEvent::class)
    ->setTask('add_to_basket', new AddProductToBasketTask($session->getBasket()))
    ->setTask('reserve_stock', new WarehouseReserveStockTask());

$product = new TShirt();

$events = await $eventDispatcher->dispatchEvent(new AddProductToBasketEvent($product));
```

Both tasks `add_to_basket` and `reserve_stock` are called [asynchronously](https://docs.hhvm.com/hack/async/introduction), and each task receives a different copy of the event. To inspect the event for each task `dispatchEvent()` returns a `Map`.

```
class HH\Map (2) {
  public $add_to_basket =>
  class AddProductToBasketEvent#2 (1) {
    public $product =>
    class TShirt#1 {}
  }
  public $reserve_stock =>
  class AddProductToBasketEvent#3 (1) {
  public $product =>
    class TShirt#1 {}
  }
}

```

A more complex example of placing an order.

```
$eventDispatcher->tasksForEvent(PlaceOrderEvent::class)
    ->setTask(
        'process_order',
        // Synchronous task groups will propagate the event to the subtasks in order. Event propagation can
        // be stopped by any of the subtasks, which then triggers the propagation-stopped tasks instead.
        // None of these tasks will prevent other tasks outside of this group from running however.
        SynchronousTaskGroup::newGroup()
            ->addTask(new ProcessPaymentTask(), 0)
            ->addTask(new WarehouseDispatchTask(), 1)
            ->addPropagationStoppedTask(new OrderProcessFailedTask())
            ->addPropagationStoppedTask(new LogToDatabaseTask()))
    ->setTask(
        'logging',
        // Asynchronous task groups will propagate the event to the subtasks at the same time. Each subtasks
        // can modify the event, however stopping propagation is not allowed as it will be unsafe.
        AsynchronousTaskGroup::newGroup()
            ->addTask(new LogToDatabaseTask())
            ->addTask(new LogToFilesystemTask()));

$order = new Order($session->getCustomer(), $session->getBasket());
$event = new PlaceOrderEvent($order);

// Dispatch the event, and return the finished event for a particular task.
$finishedEvent = await $eventDispatcher->dispatchEventForTask($event, 'process_order');

if ($finishedEvent->isPropagationStopped()) {
    // We know if the order failed by checking whether or not the event propagation was stopped.
    // PlaceOrderEvent could implement logic to store error information for handling here.
    print "Sorry, {$finishedEvent->getFailureReason()}";
} else {
    print "Order successful!";
}

// We need to finish any outstanding tasks that were not awaited. This happens automatically when the
// dispatcher is destroyed, however can be triggered manually if the application terminates a
// significant amount of time after these operations.
await $eventDispatcher->flush();
```

### Running tests

[](#running-tests)

```
hhvm vendor/bin/phpunit
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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/5589906?v=4)[Jake Wise](/maintainers/GroovyCarrot)[@GroovyCarrot](https://github.com/GroovyCarrot)

---

Top Contributors

[![GroovyCarrot](https://avatars.githubusercontent.com/u/5589906?v=4)](https://github.com/GroovyCarrot "GroovyCarrot (11 commits)")

### Embed Badge

![Health badge](/badges/groovycarrot-event-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/groovycarrot-event-dispatcher/health.svg)](https://phpackages.com/packages/groovycarrot-event-dispatcher)
```

###  Alternatives

[panphp/pan

A simple, lightweight, and privacy-focused product analytics php package.

1.3k106.0k5](/packages/panphp-pan)[sylius/promotion

Flexible promotion management for PHP applications.

28495.4k13](/packages/sylius-promotion)

PHPackages © 2026

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