Skip to content

Commit 4daee24

Browse files
committed
Improve documentation
1 parent 17f8f85 commit 4daee24

File tree

3 files changed

+64
-46
lines changed

3 files changed

+64
-46
lines changed

README.md

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ event loop implementation first or they will throw a `BadMethodCallException` on
351351
A `stream_select()` based event loop.
352352

353353
This uses the [`stream_select()`](https://www.php.net/manual/en/function.stream-select.php)
354-
function and is the only implementation which works out of the box with PHP.
354+
function and is the only implementation that works out of the box with PHP.
355355

356356
This event loop works out of the box on PHP 5.3 through PHP 7+ and HHVM.
357357
This means that no installation is required and this library works on all
@@ -468,7 +468,7 @@ run the event loop until there are no more tasks to perform.
468468

469469
For many applications, this method is the only directly visible
470470
invocation on the event loop.
471-
As a rule of thumb, it is usally recommended to attach everything to the
471+
As a rule of thumb, it is usually recommended to attach everything to the
472472
same loop instance and then run the loop once at the bottom end of the
473473
application.
474474

@@ -486,7 +486,7 @@ run it will result in the application exiting without actually waiting
486486
for any of the attached listeners.
487487

488488
This method MUST NOT be called while the loop is already running.
489-
This method MAY be called more than once after it has explicity been
489+
This method MAY be called more than once after it has explicitly been
490490
[`stop()`ped](#stop) or after it automatically stopped because it
491491
previously did no longer have anything to do.
492492

@@ -515,18 +515,21 @@ on a loop instance that has already been stopped has no effect.
515515
The `addTimer(float $interval, callable $callback): TimerInterface` method can be used to
516516
enqueue a callback to be invoked once after the given interval.
517517

518-
The timer callback function MUST be able to accept a single parameter,
519-
the timer instance as also returned by this method or you MAY use a
520-
function which has no parameters at all.
518+
The second parameter MUST be a timer callback function that accepts
519+
the timer instance as its only parameter.
520+
If you don't use the timer instance inside your timer callback function
521+
you MAY use a function which has no parameters at all.
521522

522523
The timer callback function MUST NOT throw an `Exception`.
523524
The return value of the timer callback function will be ignored and has
524525
no effect, so for performance reasons you're recommended to not return
525526
any excessive data structures.
526527

528+
This method returns a timer instance. The same timer instance will also be
529+
passed into the timer callback function as described above.
530+
You can invoke [`cancelTimer`](#canceltimer) to cancel a pending timer.
527531
Unlike [`addPeriodicTimer()`](#addperiodictimer), this method will ensure
528532
the callback will be invoked only once after the given interval.
529-
You can invoke [`cancelTimer`](#canceltimer) to cancel a pending timer.
530533

531534
```php
532535
$loop->addTimer(0.8, function () {
@@ -581,15 +584,18 @@ See also [event loop implementations](#loop-implementations) for more details.
581584
The `addPeriodicTimer(float $interval, callable $callback): TimerInterface` method can be used to
582585
enqueue a callback to be invoked repeatedly after the given interval.
583586

584-
The timer callback function MUST be able to accept a single parameter,
585-
the timer instance as also returned by this method or you MAY use a
586-
function which has no parameters at all.
587+
The second parameter MUST be a timer callback function that accepts
588+
the timer instance as its only parameter.
589+
If you don't use the timer instance inside your timer callback function
590+
you MAY use a function which has no parameters at all.
587591

588592
The timer callback function MUST NOT throw an `Exception`.
589593
The return value of the timer callback function will be ignored and has
590594
no effect, so for performance reasons you're recommended to not return
591595
any excessive data structures.
592596

597+
This method returns a timer instance. The same timer instance will also be
598+
passed into the timer callback function as described above.
593599
Unlike [`addTimer()`](#addtimer), this method will ensure the callback
594600
will be invoked infinitely after the given interval or until you invoke
595601
[`cancelTimer`](#canceltimer).
@@ -720,9 +726,10 @@ register a listener to be notified when a signal has been caught by this process
720726
This is useful to catch user interrupt signals or shutdown signals from
721727
tools like `supervisor` or `systemd`.
722728

723-
The listener callback function MUST be able to accept a single parameter,
724-
the signal added by this method or you MAY use a function which
725-
has no parameters at all.
729+
The second parameter MUST be a listener callback function that accepts
730+
the signal as its only parameter.
731+
If you don't use the signal inside your listener callback function
732+
you MAY use a function which has no parameters at all.
726733

727734
The listener callback function MUST NOT throw an `Exception`.
728735
The return value of the listener callback function will be ignored and has
@@ -737,14 +744,14 @@ $loop->addSignal(SIGINT, function (int $signal) {
737744

738745
See also [example #4](examples).
739746

740-
Signaling is only available on Unix-like platform, Windows isn't
747+
Signaling is only available on Unix-like platforms, Windows isn't
741748
supported due to operating system limitations.
742749
This method may throw a `BadMethodCallException` if signals aren't
743750
supported on this platform, for example when required extensions are
744751
missing.
745752

746753
**Note: A listener can only be added once to the same signal, any
747-
attempts to add it more then once will be ignored.**
754+
attempts to add it more than once will be ignored.**
748755

749756
#### removeSignal()
750757

@@ -775,9 +782,10 @@ react to this event with a single listener and then dispatch from this
775782
listener. This method MAY throw an `Exception` if the given resource type
776783
is not supported by this loop implementation.
777784

778-
The listener callback function MUST be able to accept a single parameter,
779-
the stream resource added by this method or you MAY use a function which
780-
has no parameters at all.
785+
The second parameter MUST be a listener callback function that accepts
786+
the stream resource as its only parameter.
787+
If you don't use the stream resource inside your listener callback function
788+
you MAY use a function which has no parameters at all.
781789

782790
The listener callback function MUST NOT throw an `Exception`.
783791
The return value of the listener callback function will be ignored and has
@@ -827,9 +835,10 @@ react to this event with a single listener and then dispatch from this
827835
listener. This method MAY throw an `Exception` if the given resource type
828836
is not supported by this loop implementation.
829837

830-
The listener callback function MUST be able to accept a single parameter,
831-
the stream resource added by this method or you MAY use a function which
832-
has no parameters at all.
838+
The second parameter MUST be a listener callback function that accepts
839+
the stream resource as its only parameter.
840+
If you don't use the stream resource inside your listener callback function
841+
you MAY use a function which has no parameters at all.
833842

834843
The listener callback function MUST NOT throw an `Exception`.
835844
The return value of the listener callback function will be ignored and has
@@ -871,7 +880,7 @@ to remove a stream that was never added or is invalid has no effect.
871880

872881
## Install
873882

874-
The recommended way to install this library is [through Composer](https://getcomposer.org).
883+
The recommended way to install this library is [through Composer](https://getcomposer.org/).
875884
[New to Composer?](https://getcomposer.org/doc/00-intro.md)
876885

877886
This project follows [SemVer](https://semver.org/).
@@ -894,7 +903,7 @@ See also [event loop implementations](#loop-implementations) for more details.
894903
## Tests
895904

896905
To run the test suite, you first need to clone this repo and then install all
897-
dependencies [through Composer](https://getcomposer.org):
906+
dependencies [through Composer](https://getcomposer.org/):
898907

899908
```bash
900909
$ composer install
@@ -903,7 +912,7 @@ $ composer install
903912
To run the test suite, go to the project root and run:
904913

905914
```bash
906-
$ php vendor/bin/phpunit
915+
$ vendor/bin/phpunit
907916
```
908917

909918
## License

src/LoopInterface.php

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ interface LoopInterface
2020
* listener. This method MAY throw an `Exception` if the given resource type
2121
* is not supported by this loop implementation.
2222
*
23-
* The listener callback function MUST be able to accept a single parameter,
24-
* the stream resource added by this method or you MAY use a function which
25-
* has no parameters at all.
23+
* The second parameter MUST be a listener callback function that accepts
24+
* the stream resource as its only parameter.
25+
* If you don't use the stream resource inside your listener callback function
26+
* you MAY use a function which has no parameters at all.
2627
*
2728
* The listener callback function MUST NOT throw an `Exception`.
2829
* The return value of the listener callback function will be ignored and has
@@ -69,9 +70,10 @@ public function addReadStream($stream, $listener);
6970
* listener. This method MAY throw an `Exception` if the given resource type
7071
* is not supported by this loop implementation.
7172
*
72-
* The listener callback function MUST be able to accept a single parameter,
73-
* the stream resource added by this method or you MAY use a function which
74-
* has no parameters at all.
73+
* The second parameter MUST be a listener callback function that accepts
74+
* the stream resource as its only parameter.
75+
* If you don't use the stream resource inside your listener callback function
76+
* you MAY use a function which has no parameters at all.
7577
*
7678
* The listener callback function MUST NOT throw an `Exception`.
7779
* The return value of the listener callback function will be ignored and has
@@ -133,18 +135,21 @@ public function removeWriteStream($stream);
133135
/**
134136
* Enqueue a callback to be invoked once after the given interval.
135137
*
136-
* The timer callback function MUST be able to accept a single parameter,
137-
* the timer instance as also returned by this method or you MAY use a
138-
* function which has no parameters at all.
138+
* The second parameter MUST be a timer callback function that accepts
139+
* the timer instance as its only parameter.
140+
* If you don't use the timer instance inside your timer callback function
141+
* you MAY use a function which has no parameters at all.
139142
*
140143
* The timer callback function MUST NOT throw an `Exception`.
141144
* The return value of the timer callback function will be ignored and has
142145
* no effect, so for performance reasons you're recommended to not return
143146
* any excessive data structures.
144147
*
148+
* This method returns a timer instance. The same timer instance will also be
149+
* passed into the timer callback function as described above.
150+
* You can invoke [`cancelTimer`](#canceltimer) to cancel a pending timer.
145151
* Unlike [`addPeriodicTimer()`](#addperiodictimer), this method will ensure
146152
* the callback will be invoked only once after the given interval.
147-
* You can invoke [`cancelTimer`](#canceltimer) to cancel a pending timer.
148153
*
149154
* ```php
150155
* $loop->addTimer(0.8, function () {
@@ -204,16 +209,19 @@ public function addTimer($interval, $callback);
204209
/**
205210
* Enqueue a callback to be invoked repeatedly after the given interval.
206211
*
207-
* The timer callback function MUST be able to accept a single parameter,
208-
* the timer instance as also returned by this method or you MAY use a
209-
* function which has no parameters at all.
212+
* The second parameter MUST be a timer callback function that accepts
213+
* the timer instance as its only parameter.
214+
* If you don't use the timer instance inside your timer callback function
215+
* you MAY use a function which has no parameters at all.
210216
*
211217
* The timer callback function MUST NOT throw an `Exception`.
212218
* The return value of the timer callback function will be ignored and has
213219
* no effect, so for performance reasons you're recommended to not return
214220
* any excessive data structures.
215221
*
216-
* Unlike [`addTimer()`](#addtimer), this method will ensure the callback
222+
* This method returns a timer instance. The same timer instance will also be
223+
* passed into the timer callback function as described above.
224+
* Unlike [`addTimer()`](#addtimer), this method will ensure the callback
217225
* will be invoked infinitely after the given interval or until you invoke
218226
* [`cancelTimer`](#canceltimer).
219227
*
@@ -356,9 +364,10 @@ public function futureTick($listener);
356364
* This is useful to catch user interrupt signals or shutdown signals from
357365
* tools like `supervisor` or `systemd`.
358366
*
359-
* The listener callback function MUST be able to accept a single parameter,
360-
* the signal added by this method or you MAY use a function which
361-
* has no parameters at all.
367+
* The second parameter MUST be a listener callback function that accepts
368+
* the signal as its only parameter.
369+
* If you don't use the signal inside your listener callback function
370+
* you MAY use a function which has no parameters at all.
362371
*
363372
* The listener callback function MUST NOT throw an `Exception`.
364373
* The return value of the listener callback function will be ignored and has
@@ -373,14 +382,14 @@ public function futureTick($listener);
373382
*
374383
* See also [example #4](examples).
375384
*
376-
* Signaling is only available on Unix-like platform, Windows isn't
385+
* Signaling is only available on Unix-like platforms, Windows isn't
377386
* supported due to operating system limitations.
378387
* This method may throw a `BadMethodCallException` if signals aren't
379388
* supported on this platform, for example when required extensions are
380389
* missing.
381390
*
382391
* **Note: A listener can only be added once to the same signal, any
383-
* attempts to add it more then once will be ignored.**
392+
* attempts to add it more than once will be ignored.**
384393
*
385394
* @param int $signal
386395
* @param callable $listener
@@ -413,7 +422,7 @@ public function removeSignal($signal, $listener);
413422
*
414423
* For many applications, this method is the only directly visible
415424
* invocation on the event loop.
416-
* As a rule of thumb, it is usally recommended to attach everything to the
425+
* As a rule of thumb, it is usually recommended to attach everything to the
417426
* same loop instance and then run the loop once at the bottom end of the
418427
* application.
419428
*
@@ -431,7 +440,7 @@ public function removeSignal($signal, $listener);
431440
* for any of the attached listeners.
432441
*
433442
* This method MUST NOT be called while the loop is already running.
434-
* This method MAY be called more than once after it has explicity been
443+
* This method MAY be called more than once after it has explicitly been
435444
* [`stop()`ped](#stop) or after it automatically stopped because it
436445
* previously did no longer have anything to do.
437446
*

src/StreamSelectLoop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* A `stream_select()` based event loop.
1111
*
1212
* This uses the [`stream_select()`](https://www.php.net/manual/en/function.stream-select.php)
13-
* function and is the only implementation which works out of the box with PHP.
13+
* function and is the only implementation that works out of the box with PHP.
1414
*
1515
* This event loop works out of the box on PHP 5.4 through PHP 7+ and HHVM.
1616
* This means that no installation is required and this library works on all

0 commit comments

Comments
 (0)