Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Queued closure listeners #33463

Merged
merged 7 commits into from Jul 8, 2020
Merged

Conversation

taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Jul 7, 2020

It is currently impossible to define a Closure based event listener that should also be queued. This adds that functionality.

This is also the first addition of a namespaced function to Laravel.

use function Illuminate\Events\queueable;

Event::listen(queueable(function (Something $event) {
    //
});

In addition, catch, onConnection, onQueue, and delay methods are available:

Event::listen(queueable(function (Something $event) {
    //
})->catch(function (Something $event, $exception) {
    //
})->onConnection(null)->onQueue(null)->delay(now()->addSeconds(10)));

This may also be used with model event listeners:

App\User::created(queueable(function ($user) {
    info($user->name);
}));

* @param \Closure $closure
* @return \Illuminate\Events\QueuedClosure
*/
function queueable(Closure $closure)
Copy link

@ghost ghost Jul 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can side effect?

Can be like?;

if (! function_exists('queueable')) {
// method here
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's namespaced.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need the if method exists, actually. The function can still conflict with a global install of itself.

* @param \Closure $closure
* @return \Illuminate\Events\QueuedClosure
*/
function queueable(Closure $closure)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still need the if method exists, actually. The function can still conflict with a global install of itself.

@GrahamCampbell GrahamCampbell changed the title Queued closure listeners [8.x] Queued closure listeners Jul 7, 2020
@taylorotwell taylorotwell merged commit 6520552 into master Jul 8, 2020
@GrahamCampbell GrahamCampbell deleted the queued-closure-listeners branch July 8, 2020 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants