Future::ignore
(PHP 8.6+, True Async 1.0)
public function ignore(): Future
Marks the Future as ignored. If the Future completes with an error and the error is not handled, it will not be passed to the event loop’s unhandled exception handler. Useful for “fire-and-forget” tasks where the result does not matter.
Return value
Future — returns the same Future for method chaining.
Examples
Example #1 Ignoring Future errors
<?php
use Async\Future;
// Launch a task whose errors we don't care about
\Async\async(function() {
// This operation may fail
sendAnalytics(['event' => 'page_view']);
})->ignore();
// The error will not be passed to the event loop handler
Example #2 Using ignore with method chaining
<?php
use Async\Future;
function warmupCache(array $keys): void {
foreach ($keys as $key) {
\Async\async(function() use ($key) {
$data = loadFromDatabase($key);
saveToCache($key, $data);
})->ignore(); // Cache errors are not critical
}
}
warmupCache(['user:1', 'user:2', 'user:3']);
See also
- Future::catch — Handle a Future error
- Future::finally — Callback on Future completion