From e7a40c0cafe0beb31941215142b591f108731409 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 21 May 2012 11:02:43 -0500 Subject: [PATCH] Updating event docs. --- laravel/documentation/events.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/laravel/documentation/events.md b/laravel/documentation/events.md index dc74745f..e678bb5e 100644 --- a/laravel/documentation/events.md +++ b/laravel/documentation/events.md @@ -5,6 +5,7 @@ ## Contents - [The Basics](#the-basics) - [Firing Events](#firing-events) - [Listening To Events](#listening-to-events) +- [Queued Events](#queued-events) - [Laravel Events](#laravel-events) @@ -51,6 +52,32 @@ #### Registering an event handler: The Closure we provided to the method will be executed each time the "loaded" event is fired. + +## Queued Events + +Sometimes you may wish to "queue" an event for firing, but not fire it immediately. This is possible using the `queue` and `flush` methods. First, throw an event on a given queue with a unique identifier: + +#### Registering a queued event: + + Event::queue('foo', $user->id, array($user)); + +This method accepts three parameters. The first is the name of the queue, the second is a unique identifier for this item on the queue, and the third is an array of data to pass to the queue flusher. + +Next, we'll register a flusher for the `foo` queue: + +#### Registering an event flusher: + + Event::flusher('foo', function($key, $user) + { + // + }); + +Note that the event flusher receives two arguments. The first, is the unique identifier for the queued event, which in this case would be the user's ID. The second (and any remaining) parameters would be the payload items for the queued event. + +Finally, we can run our flusher and flush all queued events using the `flush` method: + + Event::flush('foo'); + ## Laravel Events