Skip to content

Commit 9f10e11

Browse files
authored
Merge pull request #240 from SimonFrings/docs
2 parents 1d999e1 + 4daee24 commit 9f10e11

File tree

3 files changed

+69
-51
lines changed

3 files changed

+69
-51
lines changed

README.md

Lines changed: 36 additions & 27 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
@@ -469,7 +469,7 @@ run the event loop until there are no more tasks to perform.
469469

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

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

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

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

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

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

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

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

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

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

594-
Unlike [`addTimer()`](#addtimer), this method will ensure the the
595-
callback will be invoked infinitely after the given interval or until you
596-
invoke [`cancelTimer`](#canceltimer).
598+
This method returns a timer instance. The same timer instance will also be
599+
passed into the timer callback function as described above.
600+
Unlike [`addTimer()`](#addtimer), this method will ensure the callback
601+
will be invoked infinitely after the given interval or until you invoke
602+
[`cancelTimer`](#canceltimer).
597603

598604
```php
599605
$timer = $loop->addPeriodicTimer(0.1, function () {
@@ -721,9 +727,10 @@ register a listener to be notified when a signal has been caught by this process
721727
This is useful to catch user interrupt signals or shutdown signals from
722728
tools like `supervisor` or `systemd`.
723729

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

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

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

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

747754
**Note: A listener can only be added once to the same signal, any
748-
attempts to add it more then once will be ignored.**
755+
attempts to add it more than once will be ignored.**
749756

750757
#### removeSignal()
751758

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

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

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

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

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

873882
## Install
874883

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

878887
This project follows [SemVer](https://semver.org/).
@@ -895,7 +904,7 @@ See also [event loop implementations](#loop-implementations) for more details.
895904
## Tests
896905

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

900909
```bash
901910
$ composer install
@@ -904,7 +913,7 @@ $ composer install
904913
To run the test suite, go to the project root and run:
905914

906915
```bash
907-
$ php vendor/bin/phpunit
916+
$ vendor/bin/phpunit
908917
```
909918

910919
## License

src/LoopInterface.php

Lines changed: 32 additions & 23 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,18 +209,21 @@ 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 the
217-
* callback will be invoked infinitely after the given interval or until you
218-
* invoke [`cancelTimer`](#canceltimer).
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
225+
* will be invoked infinitely after the given interval or until you invoke
226+
* [`cancelTimer`](#canceltimer).
219227
*
220228
* ```php
221229
* $timer = $loop->addPeriodicTimer(0.1, function () {
@@ -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)