Skip to content

Commit

Permalink
[11.x] helpers.md - Cancelling deferred functions (#9902)
Browse files Browse the repository at this point in the history
* mention defer forget method

* formatting

* remove word

* wording

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
rbadillap and taylorotwell authored Sep 18, 2024
1 parent ebbf48e commit 358fd26
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,17 @@ By default, deferred functions will only be executed if the HTTP response, Artis
defer(fn () => Metrics::reportOrder($order))->always();
```

<a name="cancelling-deferred-functions"></a>
#### Cancelling Deferred Functions

If you need to cancel a deferred function before it is executed, you can use the `forget` method to cancel the function by its name. To name a deferred function, provide a second argument to the `defer` function:

```php
defer(fn () => Metrics::report(), 'reportMetrics');

defer()->forget('reportMetrics');
```

<a name="deferred-function-compatibility"></a>
#### Deferred Function Compatibility

Expand Down

0 comments on commit 358fd26

Please sign in to comment.