ISignalHandler
in
Interface that lets a command cooperatively check whether it was interrupted by the user (Ctrl-C/SIGTERM) and abort accordingly.
#[AsCommand(name: 'app:long-running-task')]
class LongRunningTaskCommand {
public function __invoke(IOutput $output, ISignalHandler $signalHandler): ExitCode {
try {
foreach ($this->items() as $item) {
$signalHandler->abortIfInterrupted();
$this->process($item);
}
} catch (InterruptedException) {
$output->writeln('Interrupted by user');
return ExitCode::Failure;
}
return ExitCode::Success;
}
}
Tags
Attributes
- #[Consumable]
- $since: '35.0.0'
Table of Contents
Methods
- abortIfInterrupted() : void
- Throw when interrupted by user (Ctrl-C/SIGTERM)
Methods
abortIfInterrupted()
Throw when interrupted by user (Ctrl-C/SIGTERM)
public
abortIfInterrupted() : void