Skip to content

Conversation

@WendellAdriel
Copy link
Contributor

This adds a defer() method to Http::batch following the same pattern used in Concurrency::defer.

Http::batch(fn (Batch $batch) => [
    $batch->get('https://example.com/endpoint-1'),
    $batch->get('https://example.com/endpoint-2'),
])->before(function (Batch $batch) {
    // The batch has been created but no requests have been initialized...
})->progress(function (Batch $batch, int|string $key, Response $response) {
    // An individual request has completed successfully...
})->then(function (Batch $batch, array $results) {
    // All requests completed successfully...
})->catch(function (Batch $batch, int|string $key, Response|RequestException $response) {
    // First batch request failure detected...
})->finally(function (Batch $batch, array $results) {
    // The batch has finished executing...
})->defer();

This can be handy when we don't need the results, but we want to trigger actions with the hooks, so this can be done without affecting the performance and the response that we need to send back to the users.

@taylorotwell taylorotwell merged commit 8a093cd into laravel:12.x Oct 14, 2025
66 checks passed
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.

2 participants