Skip to content

Commit 5bd7794

Browse files
committed
Merge pull request #63 from async-interop/throw-on-invalid-watcher
Throw on invalid watcher identifier
2 parents 6449495 + b8f0d52 commit 5bd7794

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/Loop.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Interop\Async\Loop\Driver;
66
use Interop\Async\Loop\DriverFactory;
7+
use Interop\Async\Loop\InvalidWatcherException;
8+
use Interop\Async\Loop\UnsupportedFeatureException;
79

810
final class Loop
911
{
@@ -209,6 +211,8 @@ public static function onWritable($stream, callable $callback, $data = null)
209211
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
210212
*
211213
* @return string An identifier that can be used to cancel, enable or disable the watcher.
214+
*
215+
* @throws UnsupportedFeatureException Thrown if signal handling is not supported.
212216
*/
213217
public static function onSignal($signo, callable $callback, $data = null)
214218
{
@@ -221,6 +225,8 @@ public static function onSignal($signo, callable $callback, $data = null)
221225
* @param string $watcherId The watcher identifier.
222226
*
223227
* @return void
228+
*
229+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
224230
*/
225231
public static function enable($watcherId)
226232
{
@@ -233,6 +239,8 @@ public static function enable($watcherId)
233239
* @param string $watcherId The watcher identifier.
234240
*
235241
* @return void
242+
*
243+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
236244
*/
237245
public static function disable($watcherId)
238246
{
@@ -245,6 +253,8 @@ public static function disable($watcherId)
245253
* @param string $watcherId The watcher identifier.
246254
*
247255
* @return void
256+
*
257+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
248258
*/
249259
public static function cancel($watcherId)
250260
{
@@ -260,6 +270,8 @@ public static function cancel($watcherId)
260270
* @param string $watcherId The watcher identifier.
261271
*
262272
* @return void
273+
*
274+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
263275
*/
264276
public static function reference($watcherId)
265277
{
@@ -275,6 +287,8 @@ public static function reference($watcherId)
275287
* @param string $watcherId The watcher identifier.
276288
*
277289
* @return void
290+
*
291+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
278292
*/
279293
public static function unreference($watcherId)
280294
{

src/Loop/Driver.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function onWritable($stream, callable $callback, $data = null);
9494
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
9595
*
9696
* @return string An identifier that can be used to cancel, enable or disable the watcher.
97+
*
98+
* @throws UnsupportedFeatureException Thrown if signal handling is not supported.
9799
*/
98100
public function onSignal($signo, callable $callback, $data = null);
99101

@@ -103,15 +105,19 @@ public function onSignal($signo, callable $callback, $data = null);
103105
* @param string $watcherId The watcher identifier.
104106
*
105107
* @return void
108+
*
109+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
106110
*/
107111
public function enable($watcherId);
108112

109113
/**
110-
* Disable a watcher.
114+
* Disable a watcher. Disabling a watcher MUST NOT invalidate the watcher.
111115
*
112116
* @param string $watcherId The watcher identifier.
113117
*
114118
* @return void
119+
*
120+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
115121
*/
116122
public function disable($watcherId);
117123

@@ -121,6 +127,8 @@ public function disable($watcherId);
121127
* @param string $watcherId The watcher identifier.
122128
*
123129
* @return void
130+
*
131+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
124132
*/
125133
public function cancel($watcherId);
126134

@@ -133,6 +141,8 @@ public function cancel($watcherId);
133141
* @param string $watcherId The watcher identifier.
134142
*
135143
* @return void
144+
*
145+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
136146
*/
137147
public function reference($watcherId);
138148

@@ -145,6 +155,8 @@ public function reference($watcherId);
145155
* @param string $watcherId The watcher identifier.
146156
*
147157
* @return void
158+
*
159+
* @throws InvalidWatcherException Thrown if the watcher identifier is invalid or cancelled.
148160
*/
149161
public function unreference($watcherId);
150162

src/Loop/InvalidWatcherException.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Interop\Async\Loop;
4+
5+
/**
6+
* Must be thrown if an operation is attempted with an invalid watcher identifier.
7+
*/
8+
class InvalidWatcherException extends \LogicException
9+
{
10+
11+
}

0 commit comments

Comments
 (0)