Skip to content

Commit d431fa7

Browse files
committed
Update signal handling documentation
1 parent 742e5c6 commit d431fa7

2 files changed

Lines changed: 52 additions & 27 deletions

File tree

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ See also [example #3](examples).
313313
### addSignal()
314314

315315
The `addSignal(int $signal, callable $listener): void` method can be used to
316-
be notified about OS signals. This is useful to catch user interrupt signals or
317-
shutdown signals from tools like `supervisor` or `systemd`.
316+
register a listener to be notified when a signal has been caught by this process.
317+
318+
This is useful to catch user interrupt signals or shutdown signals from
319+
tools like `supervisor` or `systemd`.
318320

319321
The listener callback function MUST be able to accept a single parameter,
320322
the signal added by this method or you MAY use a function which
@@ -326,32 +328,32 @@ no effect, so for performance reasons you're recommended to not return
326328
any excessive data structures.
327329

328330
```php
329-
$listener = function (int $signal) {
330-
echo 'Caught user iterrupt signal', PHP_EOL;
331-
};
332-
$loop->addSignal(SIGINT, $listener);
331+
$loop->addSignal(SIGINT, function (int $signal) {
332+
echo 'Caught user interrupt signal' . PHP_EOL;
333+
});
333334
```
334335

335336
See also [example #4](examples).
336337

337-
**Note: A listener can only be added once to the same signal, any attempts to add it
338-
more then once will be ignored.**
338+
Signaling is only available on Unix-like platform, Windows isn't
339+
supported due to operating system limitations.
340+
This method may throw a `BadMethodCallException` if signals aren't
341+
supported on this platform, for example when required extensions are
342+
missing.
339343

340-
**Note: Signaling is only available on Unix-like platform, Windows isn't supported due
341-
to limitations from underlying signal handlers.**
344+
**Note: A listener can only be added once to the same signal, any
345+
attempts to add it more then once will be ignored.**
342346

343347
### removeSignal()
344348

345-
The `removeSignal(int $signal, callable $listener): void` removes a previously added
346-
signal listener.
347-
348-
Any attempts to remove listeners that aren't registerred will be ignored.
349+
The `removeSignal(int $signal, callable $listener): void` method can be used to
350+
remove a previously added signal listener.
349351

350352
```php
351353
$loop->removeSignal(SIGINT, $listener);
352354
```
353355

354-
See also [example #4](examples).
356+
Any attempts to remove listeners that aren't registered will be ignored.
355357

356358
### addReadStream()
357359

src/LoopInterface.php

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,32 +317,55 @@ public function isTimerActive(TimerInterface $timer);
317317
public function futureTick(callable $listener);
318318

319319
/**
320-
* Registers a signal listener with the loop, which
321-
* on it's turn registers it with a signal handler
322-
* suitable for the loop implementation.
320+
* Register a listener to be notified when a signal has been caught by this process.
323321
*
324-
* A listener can only be added once, any attempts
325-
* to add it again will be ignored.
322+
* This is useful to catch user interrupt signals or shutdown signals from
323+
* tools like `supervisor` or `systemd`.
324+
*
325+
* The listener callback function MUST be able to accept a single parameter,
326+
* the signal added by this method or you MAY use a function which
327+
* has no parameters at all.
328+
*
329+
* The listener callback function MUST NOT throw an `Exception`.
330+
* The return value of the listener callback function will be ignored and has
331+
* no effect, so for performance reasons you're recommended to not return
332+
* any excessive data structures.
333+
*
334+
* ```php
335+
* $loop->addSignal(SIGINT, function (int $signal) {
336+
* echo 'Caught user interrupt signal' . PHP_EOL;
337+
* });
338+
* ```
326339
*
327340
* See also [example #4](examples).
328341
*
342+
* Signaling is only available on Unix-like platform, Windows isn't
343+
* supported due to operating system limitations.
344+
* This method may throw a `BadMethodCallException` if signals aren't
345+
* supported on this platform, for example when required extensions are
346+
* missing.
347+
*
348+
* **Note: A listener can only be added once to the same signal, any
349+
* attempts to add it more then once will be ignored.**
350+
*
329351
* @param int $signal
330352
* @param callable $listener
331353
*
332-
* @throws \BadMethodCallException when signals
333-
* aren't supported by the loop, e.g. when required
334-
* extensions are missing.
354+
* @throws \BadMethodCallException when signals aren't supported on this
355+
* platform, for example when required extensions are missing.
335356
*
336357
* @return void
337358
*/
338359
public function addSignal($signal, callable $listener);
339360

340361
/**
341-
* Removed previous registered signal listener from
342-
* the loop, which on it's turn removes it from the
343-
* underlying signal handler.
362+
* Removes a previously added signal listener.
344363
*
345-
* See also [example #4](examples).
364+
* ```php
365+
* $loop->removeSignal(SIGINT, $listener);
366+
* ```
367+
*
368+
* Any attempts to remove listeners that aren't registered will be ignored.
346369
*
347370
* @param int $signal
348371
* @param callable $listener

0 commit comments

Comments
 (0)