dispatch_sync vs. notifyNow #46967
Replies: 2 comments 1 reply
-
To improve performance, you can queue notifications instead of sending them immediately. To do this, implement the ShouldQueue interface and use the Queueable trait in your notification class. use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Illuminate\Bus\Queueable; Updating the class definition to implement the ShouldQueue interface and use the Queueable trait: class MyNotification extends Notification implements ShouldQueue
{
use Queueable;
// ...
} This is the most important part as it makes the behavior of the class now asynchronous (rather than synchronously) as notifications will be queued and processed in the background (which is a design to improve the overall performance of an application) |
Beta Was this translation helpful? Give feedback.
-
Hi Laravel uses I may be wrong but |
Beta Was this translation helpful? Give feedback.
-
Hi!
its something very small, but when I was using job dispatching and notifications, it caught my eye that there are 2 methods which do the same but named differently. I'm talking about the methods
$user->notifyNow()
for notifications anddispatch_sync()
for jobs. Isn't it more consistent whennotifyNow()
will be changed tonotifySync()
?Beta Was this translation helpful? Give feedback.
All reactions