Skip to content

Commit badd47c

Browse files
committed
Improve documentation
1 parent 17f8f85 commit badd47c

File tree

3 files changed

+56
-46
lines changed

3 files changed

+56
-46
lines changed

README.md

Lines changed: 29 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,9 +515,10 @@ 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 also returned by the `addTimer` method 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
@@ -581,9 +582,10 @@ See also [event loop implementations](#loop-implementations) for more details.
581582
The `addPeriodicTimer(float $interval, callable $callback): TimerInterface` method can be used to
582583
enqueue a callback to be invoked repeatedly after the given interval.
583584

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.
585+
The second parameter MUST be a timer callback function that accepts
586+
the timer instance also returned by the `addPeriodicTimer` method as its only parameter.
587+
If you don't use the timer instance inside your timer callback function
588+
you MAY use a function which has no parameters at all.
587589

588590
The timer callback function MUST NOT throw an `Exception`.
589591
The return value of the timer callback function will be ignored and has
@@ -662,7 +664,7 @@ cancel a pending timer.
662664
See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples).
663665

664666
Calling this method on a timer instance that has not been added to this
665-
loop instance or on a timer that has already been cancelled has no effect.
667+
loop instance or on a timer that has already been canceled has no effect.
666668

667669
#### futureTick()
668670

@@ -720,9 +722,10 @@ register a listener to be notified when a signal has been caught by this process
720722
This is useful to catch user interrupt signals or shutdown signals from
721723
tools like `supervisor` or `systemd`.
722724

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.
725+
The second parameter MUST be a listener callback function that accepts
726+
the signal added by this method as its only parameter.
727+
If you don't use the signal inside your listener callback function
728+
you MAY use a function which has no parameters at all.
726729

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

738741
See also [example #4](examples).
739742

740-
Signaling is only available on Unix-like platform, Windows isn't
743+
Signaling is only available on Unix-like platforms, Windows isn't
741744
supported due to operating system limitations.
742745
This method may throw a `BadMethodCallException` if signals aren't
743746
supported on this platform, for example when required extensions are
744747
missing.
745748

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

749752
#### removeSignal()
750753

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

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.
781+
The second parameter MUST be a listener callback function that accepts
782+
the stream resource added by this method as its only parameter.
783+
If you don't use the stream resource inside your listener callback function
784+
you MAY use a function which has no parameters at all.
781785

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

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.
834+
The second parameter MUST be a listener callback function that accepts
835+
the stream resource added by this method as its only parameter.
836+
If you don't use the stream resource inside your listener callback function
837+
you MAY use a function which has no parameters at all.
833838

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

872877
## Install
873878

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

877882
This project follows [SemVer](https://semver.org/).
@@ -894,7 +899,7 @@ See also [event loop implementations](#loop-implementations) for more details.
894899
## Tests
895900

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

899904
```bash
900905
$ composer install
@@ -903,7 +908,7 @@ $ composer install
903908
To run the test suite, go to the project root and run:
904909

905910
```bash
906-
$ php vendor/bin/phpunit
911+
$ vendor/bin/phpunit
907912
```
908913

909914
## License

src/LoopInterface.php

Lines changed: 26 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 added by this method 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 added by this method 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,9 +135,10 @@ 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 also returned by the `addTimer` method 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
@@ -204,16 +207,17 @@ public function addTimer($interval, $callback);
204207
/**
205208
* Enqueue a callback to be invoked repeatedly after the given interval.
206209
*
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.
210+
* The second parameter MUST be a timer callback function that accepts
211+
* the timer instance also returned by the `addPeriodicTimer` method as its only parameter.
212+
* If you don't use the timer instance inside your timer callback function
213+
* you MAY use a function which has no parameters at all.
210214
*
211215
* The timer callback function MUST NOT throw an `Exception`.
212216
* The return value of the timer callback function will be ignored and has
213217
* no effect, so for performance reasons you're recommended to not return
214218
* any excessive data structures.
215219
*
216-
* Unlike [`addTimer()`](#addtimer), this method will ensure the callback
220+
* Unlike [`addTimer()`](#addtimer), this method will ensure the callback
217221
* will be invoked infinitely after the given interval or until you invoke
218222
* [`cancelTimer`](#canceltimer).
219223
*
@@ -290,7 +294,7 @@ public function addPeriodicTimer($interval, $callback);
290294
* See also [`addPeriodicTimer()`](#addperiodictimer) and [example #2](examples).
291295
*
292296
* Calling this method on a timer instance that has not been added to this
293-
* loop instance or on a timer that has already been cancelled has no effect.
297+
* loop instance or on a timer that has already been canceled has no effect.
294298
*
295299
* @param TimerInterface $timer The timer to cancel.
296300
*
@@ -356,9 +360,10 @@ public function futureTick($listener);
356360
* This is useful to catch user interrupt signals or shutdown signals from
357361
* tools like `supervisor` or `systemd`.
358362
*
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.
363+
* The second parameter MUST be a listener callback function that accepts
364+
* the signal added by this method as its only parameter.
365+
* If you don't use the signal inside your listener callback function
366+
* you MAY use a function which has no parameters at all.
362367
*
363368
* The listener callback function MUST NOT throw an `Exception`.
364369
* The return value of the listener callback function will be ignored and has
@@ -373,14 +378,14 @@ public function futureTick($listener);
373378
*
374379
* See also [example #4](examples).
375380
*
376-
* Signaling is only available on Unix-like platform, Windows isn't
381+
* Signaling is only available on Unix-like platforms, Windows isn't
377382
* supported due to operating system limitations.
378383
* This method may throw a `BadMethodCallException` if signals aren't
379384
* supported on this platform, for example when required extensions are
380385
* missing.
381386
*
382387
* **Note: A listener can only be added once to the same signal, any
383-
* attempts to add it more then once will be ignored.**
388+
* attempts to add it more than once will be ignored.**
384389
*
385390
* @param int $signal
386391
* @param callable $listener
@@ -413,7 +418,7 @@ public function removeSignal($signal, $listener);
413418
*
414419
* For many applications, this method is the only directly visible
415420
* invocation on the event loop.
416-
* As a rule of thumb, it is usally recommended to attach everything to the
421+
* As a rule of thumb, it is usually recommended to attach everything to the
417422
* same loop instance and then run the loop once at the bottom end of the
418423
* application.
419424
*
@@ -431,7 +436,7 @@ public function removeSignal($signal, $listener);
431436
* for any of the attached listeners.
432437
*
433438
* 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
439+
* This method MAY be called more than once after it has explicitly been
435440
* [`stop()`ped](#stop) or after it automatically stopped because it
436441
* previously did no longer have anything to do.
437442
*

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)