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

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

olvlvl/delayed-event-dispatcher
===============================

Delays the dispatching of events

v3.0(6y ago)24.3k[1 issues](https://github.com/olvlvl/delayed-event-dispatcher/issues)BSD-3-ClausePHPPHP &gt;=7.2

Since Jan 21Pushed 6y agoCompare

[ Source](https://github.com/olvlvl/delayed-event-dispatcher)[ Packagist](https://packagist.org/packages/olvlvl/delayed-event-dispatcher)[ RSS](/packages/olvlvl-delayed-event-dispatcher/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (1)Versions (7)Used By (0)

Delayed event dispatcher
========================

[](#delayed-event-dispatcher)

[![Release](https://camo.githubusercontent.com/ae8ebeaad9408d017bbe84ca100f55e2225c064b003811f840e6de5846afc587/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6c766c766c2f64656c617965642d6576656e742d646973706174636865722e737667)](https://packagist.org/packages/olvlvl/delayed-event-dispatcher)[![Build Status](https://camo.githubusercontent.com/f210228039c12e01f5d7c82bc98819df3d16f49cc08e4f5b937899c17ddb4885/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f6c766c766c2f64656c617965642d6576656e742d646973706174636865722e737667)](http://travis-ci.org/olvlvl/delayed-event-dispatcher)[![Code Quality](https://camo.githubusercontent.com/73de74ab48641253e2e404cedc3cea7a5ecd756f5cbd51d33f9567ac1fde4e97/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f6c766c766c2f64656c617965642d6576656e742d646973706174636865722e737667)](https://scrutinizer-ci.com/g/olvlvl/delayed-event-dispatcher)[![Code Coverage](https://camo.githubusercontent.com/61b7327f497433c8eaba0f5c7173b844bfed2d8fc9a5d0839aaf699ed5cbab21/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6f6c766c766c2f64656c617965642d6576656e742d646973706174636865722e737667)](https://coveralls.io/r/olvlvl/delayed-event-dispatcher)[![Packagist](https://camo.githubusercontent.com/87f2cf57167576c4b5ba5d3116d9916af0156ea9f68670c8befdf539f04b675c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6c766c766c2f64656c617965642d6576656e742d646973706174636865722e737667)](https://packagist.org/packages/olvlvl/delayed-event-dispatcher)

The `olvlvl/delayed-event-dispatcher` package provides an event dispatcher that delays event dispatching to a later time in the application life.

A delayed event dispatcher is useful to reduce the response time of your HTTP application when events can perfectly be dispatched after the response has been sent. For instance, updating an entity that would require clearing cache, performing projections, or reindexing, all of which have nothing to do with the response itself. Delayed events are dispatched when flushed, but you can choose another solution entirely, like sending them to consumers using [RabbitMQ](https://www.rabbitmq.com/)or [Kafka](https://kafka.apache.org/).

Because you're probably using one event dispatcher for your application you don't want all events to be delayed, some of them have to be dispatched immediately for your application to run properly, that's why you can specify an arbiter to determine which events to delay and which not to.

Finally, because you want all delayed events to be dispatched when you flush them—even when an exception is thrown—you can provide an exception handler. It's up to you to decide what to do. You'll probably want to recover, log the exception, and continue with dispatching the other events.

**Disclaimer:** The delayed event dispatcher is a decorator that is meant to be used together with [psr/event-dispatcher](https://github.com/php-fig/event-dispatcher).

Instantiating a delayed event dispatcher
----------------------------------------

[](#instantiating-a-delayed-event-dispatcher)

The delayed event dispatcher is a decorator, which means you'll need another event dispatcher to decorate.

```
