Skip to content

Commit 49ac483

Browse files
authored
Merge pull request #119 from clue-labs/factory-documentation
Documentation for Factory
2 parents f94c3ea + f4e9322 commit 49ac483

7 files changed

Lines changed: 34 additions & 166 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ $loop->run();
9494
purposes.
9595
3. The loop is run with a single `$loop->run()` call at the end of the program.
9696

97+
## Factory
98+
99+
The `Factory` class exists as a convenient way to pick the best available
100+
[loop implementation)(#loop-implementation).
101+
102+
The `create(): LoopInterface` method can be used to create a new loop
103+
instance:
104+
105+
```php
106+
$loop = React\EventLoop\Factory::create();
107+
```
108+
109+
This method always returns an instance implementing `LoopInterface`,
110+
the actual loop implementation is an implementation detail.
111+
112+
This method should usually only be called once at the beginning of the program.
113+
97114
## Loop implementations
98115

99116
In addition to the interface there are the following implementations provided:

src/ExtEventLoop.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ function ($signal) {
5959
$this->createStreamCallback();
6060
}
6161

62-
/**
63-
* {@inheritdoc}
64-
*/
6562
public function addReadStream($stream, callable $listener)
6663
{
6764
$key = (int) $stream;
@@ -72,9 +69,6 @@ public function addReadStream($stream, callable $listener)
7269
}
7370
}
7471

75-
/**
76-
* {@inheritdoc}
77-
*/
7872
public function addWriteStream($stream, callable $listener)
7973
{
8074
$key = (int) $stream;
@@ -85,9 +79,6 @@ public function addWriteStream($stream, callable $listener)
8579
}
8680
}
8781

88-
/**
89-
* {@inheritdoc}
90-
*/
9182
public function removeReadStream($stream)
9283
{
9384
$key = (int) $stream;
@@ -98,9 +89,6 @@ public function removeReadStream($stream)
9889
}
9990
}
10091

101-
/**
102-
* {@inheritdoc}
103-
*/
10492
public function removeWriteStream($stream)
10593
{
10694
$key = (int) $stream;
@@ -127,9 +115,6 @@ private function removeStream($stream)
127115
}
128116
}
129117

130-
/**
131-
* {@inheritdoc}
132-
*/
133118
public function addTimer($interval, callable $callback)
134119
{
135120
$timer = new Timer($interval, $callback, false);
@@ -139,9 +124,6 @@ public function addTimer($interval, callable $callback)
139124
return $timer;
140125
}
141126

142-
/**
143-
* {@inheritdoc}
144-
*/
145127
public function addPeriodicTimer($interval, callable $callback)
146128
{
147129
$timer = new Timer($interval, $callback, true);
@@ -151,9 +133,6 @@ public function addPeriodicTimer($interval, callable $callback)
151133
return $timer;
152134
}
153135

154-
/**
155-
* {@inheritdoc}
156-
*/
157136
public function cancelTimer(TimerInterface $timer)
158137
{
159138
if ($this->isTimerActive($timer)) {
@@ -162,41 +141,26 @@ public function cancelTimer(TimerInterface $timer)
162141
}
163142
}
164143

165-
/**
166-
* {@inheritdoc}
167-
*/
168144
public function isTimerActive(TimerInterface $timer)
169145
{
170146
return $this->timerEvents->contains($timer);
171147
}
172148

173-
/**
174-
* {@inheritdoc}
175-
*/
176149
public function futureTick(callable $listener)
177150
{
178151
$this->futureTickQueue->add($listener);
179152
}
180153

181-
/**
182-
* {@inheritdoc}
183-
*/
184154
public function addSignal($signal, callable $listener)
185155
{
186156
$this->signals->add($signal, $listener);
187157
}
188158

189-
/**
190-
* {@inheritdoc}
191-
*/
192159
public function removeSignal($signal, callable $listener)
193160
{
194161
$this->signals->remove($signal, $listener);
195162
}
196163

197-
/**
198-
* {@inheritdoc}
199-
*/
200164
public function run()
201165
{
202166
$this->running = true;
@@ -215,9 +179,6 @@ public function run()
215179
}
216180
}
217181

218-
/**
219-
* {@inheritdoc}
220-
*/
221182
public function stop()
222183
{
223184
$this->running = false;

src/Factory.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,25 @@
22

33
namespace React\EventLoop;
44

5+
/**
6+
* The `Factory` class exists as a convenient way to pick the best available loop implementation.
7+
*/
58
class Factory
69
{
10+
/**
11+
* Creates a new loop instance
12+
*
13+
* ```php
14+
* $loop = React\EventLoop\Factory::create();
15+
* ```
16+
*
17+
* This method always returns an instance implementing `LoopInterface`,
18+
* the actual loop implementation is an implementation detail.
19+
*
20+
* This method should usually only be called once at the beginning of the program.
21+
*
22+
* @return LoopInterface
23+
*/
724
public static function create()
825
{
926
// @codeCoverageIgnoreStart

src/LibEvLoop.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ function ($signal) {
5454
);
5555
}
5656

57-
/**
58-
* {@inheritdoc}
59-
*/
6057
public function addReadStream($stream, callable $listener)
6158
{
6259
if (isset($this->readEvents[(int) $stream])) {
@@ -73,9 +70,6 @@ public function addReadStream($stream, callable $listener)
7370
$this->readEvents[(int) $stream] = $event;
7471
}
7572

76-
/**
77-
* {@inheritdoc}
78-
*/
7973
public function addWriteStream($stream, callable $listener)
8074
{
8175
if (isset($this->writeEvents[(int) $stream])) {
@@ -92,9 +86,6 @@ public function addWriteStream($stream, callable $listener)
9286
$this->writeEvents[(int) $stream] = $event;
9387
}
9488

95-
/**
96-
* {@inheritdoc}
97-
*/
9889
public function removeReadStream($stream)
9990
{
10091
$key = (int) $stream;
@@ -105,9 +96,6 @@ public function removeReadStream($stream)
10596
}
10697
}
10798

108-
/**
109-
* {@inheritdoc}
110-
*/
11199
public function removeWriteStream($stream)
112100
{
113101
$key = (int) $stream;
@@ -118,9 +106,6 @@ public function removeWriteStream($stream)
118106
}
119107
}
120108

121-
/**
122-
* {@inheritdoc}
123-
*/
124109
public function addTimer($interval, callable $callback)
125110
{
126111
$timer = new Timer( $interval, $callback, false);
@@ -140,9 +125,6 @@ public function addTimer($interval, callable $callback)
140125
return $timer;
141126
}
142127

143-
/**
144-
* {@inheritdoc}
145-
*/
146128
public function addPeriodicTimer($interval, callable $callback)
147129
{
148130
$timer = new Timer($interval, $callback, true);
@@ -158,9 +140,6 @@ public function addPeriodicTimer($interval, callable $callback)
158140
return $timer;
159141
}
160142

161-
/**
162-
* {@inheritdoc}
163-
*/
164143
public function cancelTimer(TimerInterface $timer)
165144
{
166145
if (isset($this->timerEvents[$timer])) {
@@ -169,41 +148,26 @@ public function cancelTimer(TimerInterface $timer)
169148
}
170149
}
171150

172-
/**
173-
* {@inheritdoc}
174-
*/
175151
public function isTimerActive(TimerInterface $timer)
176152
{
177153
return $this->timerEvents->contains($timer);
178154
}
179155

180-
/**
181-
* {@inheritdoc}
182-
*/
183156
public function futureTick(callable $listener)
184157
{
185158
$this->futureTickQueue->add($listener);
186159
}
187160

188-
/**
189-
* {@inheritdoc}
190-
*/
191161
public function addSignal($signal, callable $listener)
192162
{
193163
$this->signals->add($signal, $listener);
194164
}
195165

196-
/**
197-
* {@inheritdoc}
198-
*/
199166
public function removeSignal($signal, callable $listener)
200167
{
201168
$this->signals->remove($signal, $listener);
202169
}
203170

204-
/**
205-
* {@inheritdoc}
206-
*/
207171
public function run()
208172
{
209173
$this->running = true;
@@ -222,9 +186,6 @@ public function run()
222186
}
223187
}
224188

225-
/**
226-
* {@inheritdoc}
227-
*/
228189
public function stop()
229190
{
230191
$this->running = false;

0 commit comments

Comments
 (0)