Fresh code drop

Debounce Queued Event Listeners

JAVASCRIPT

Process only the newest event when several events arrive during a short period.

JAVASCRIPT
CodeSnap // free canvas

Debounce Queued Event Listeners

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\Attributes\DebounceFor;

#[DebounceFor(30, maxWait: 120)]
class UpdateProductSearchIndex implements ShouldQueue
{
    public function debounceId(ProductUpdated $event): string
    {
        return (string) $event->product->getKey();
    }
}

Turn your code into a post.Five templates are free—no account needed.

Remix this snap