From 358fd26b3a81359b6e5f54d263f50083e82f525b Mon Sep 17 00:00:00 2001 From: Ronny Badilla Date: Wed, 18 Sep 2024 08:41:12 -0600 Subject: [PATCH] [11.x] `helpers.md` - Cancelling deferred functions (#9902) * mention defer forget method * formatting * remove word * wording --------- Co-authored-by: Taylor Otwell --- helpers.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helpers.md b/helpers.md index 884d9f9ccd..9a75390696 100644 --- a/helpers.md +++ b/helpers.md @@ -2401,6 +2401,17 @@ By default, deferred functions will only be executed if the HTTP response, Artis defer(fn () => Metrics::reportOrder($order))->always(); ``` + +#### 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'); +``` + #### Deferred Function Compatibility