Skip to content

Commit 8eb3033

Browse files
committed
Add note about watchers being enabled by default to every method creating a watcher
1 parent c2b598e commit 8eb3033

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

src/Loop.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,11 @@ public static function stop()
136136
/**
137137
* Defer the execution of a callback.
138138
*
139-
* The deferred callable MUST be executed in the next tick of the event loop and before any other type of watcher.
140-
* Order of enabling MUST be preserved when executing the callbacks.
139+
* The deferred callable MUST be executed before any other type of watcher in a tick. Order of enabling MUST be
140+
* preserved when executing the callbacks.
141+
*
142+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
143+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
141144
*
142145
* @param callable(string $watcherId, mixed $data) $callback The callback to defer. The `$watcherId` will be
143146
* invalidated before the callback call.
@@ -157,6 +160,9 @@ public static function defer(callable $callback, $data = null)
157160
* The delay is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be determined by which
158161
* timers expire first, but timers with the same expiration time MAY be executed in any order.
159162
*
163+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
164+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
165+
*
160166
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
161167
* @param callable(string $watcherId, mixed $data) $callback The callback to delay. The `$watcherId` will be
162168
* invalidated before the callback call.
@@ -177,6 +183,9 @@ public static function delay($time, callable $callback, $data = null)
177183
* determined by which timers expire first, but timers with the same expiration time MAY be executed in any order.
178184
* The first execution is scheduled after the first interval period.
179185
*
186+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
187+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
188+
*
180189
* @param int $interval The time interval, in milliseconds, to wait between executions.
181190
* @param callable(string $watcherId, mixed $data) $callback The callback to repeat.
182191
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -199,6 +208,9 @@ public static function repeat($interval, callable $callback, $data = null)
199208
*
200209
* Multiple watchers on the same stream MAY be executed in any order.
201210
*
211+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
212+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
213+
*
202214
* @param resource $stream The stream to monitor.
203215
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
204216
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -221,6 +233,9 @@ public static function onReadable($stream, callable $callback, $data = null)
221233
*
222234
* Multiple watchers on the same stream MAY be executed in any order.
223235
*
236+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
237+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
238+
*
224239
* @param resource $stream The stream to monitor.
225240
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
226241
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -242,6 +257,9 @@ public static function onWritable($stream, callable $callback, $data = null)
242257
*
243258
* Multiple watchers on the same signal MAY be executed in any order.
244259
*
260+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
261+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
262+
*
245263
* @param int $signo The signal number to monitor.
246264
* @param callable(string $watcherId, int $signo, mixed $data) $callback The callback to execute.
247265
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
@@ -257,7 +275,7 @@ public static function onSignal($signo, callable $callback, $data = null)
257275
}
258276

259277
/**
260-
* Enable a watcher.
278+
* Enable a watcher to be active starting in the next tick.
261279
*
262280
* Watchers MUST immediately be marked as enabled, but only be activated (i.e. callbacks can be called) right before
263281
* the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
@@ -275,7 +293,10 @@ public static function enable($watcherId)
275293
}
276294

277295
/**
278-
* Disable a watcher.
296+
* Disable a watcher immediately.
297+
*
298+
* A watcher MUST be disabled immediately, e.g. if a defer watcher disables a later defer watcher, the second defer
299+
* watcher isn't executed in this tick.
279300
*
280301
* Disabling a watcher MUST NOT invalidate the watcher. Calling this function MUST NOT fail, even if passed an
281302
* invalid watcher.

src/Loop/Driver.php

+25-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ abstract public function stop();
4747
/**
4848
* Defer the execution of a callback.
4949
*
50-
* The deferred callable MUST be executed in the next tick of the event loop and before any other type of watcher.
51-
* Order of enabling MUST be preserved when executing the callbacks.
50+
* The deferred callable MUST be executed before any other type of watcher in a tick. Order of enabling MUST be
51+
* preserved when executing the callbacks.
52+
*
53+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
54+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
5255
*
5356
* @param callable(string $watcherId, mixed $data) $callback The callback to defer. The `$watcherId` will be
5457
* invalidated before the callback call.
@@ -64,6 +67,9 @@ abstract public function defer(callable $callback, $data = null);
6467
* The delay is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be determined by which
6568
* timers expire first, but timers with the same expiration time MAY be executed in any order.
6669
*
70+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
71+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
72+
*
6773
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
6874
* @param callable(string $watcherId, mixed $data) $callback The callback to delay. The `$watcherId` will be
6975
* invalidated before the callback call.
@@ -80,6 +86,9 @@ abstract public function delay($delay, callable $callback, $data = null);
8086
* determined by which timers expire first, but timers with the same expiration time MAY be executed in any order.
8187
* The first execution is scheduled after the first interval period.
8288
*
89+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
90+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
91+
*
8392
* @param int $interval The time interval, in milliseconds, to wait between executions.
8493
* @param callable(string $watcherId, mixed $data) $callback The callback to repeat.
8594
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -98,6 +107,9 @@ abstract public function repeat($interval, callable $callback, $data = null);
98107
*
99108
* Multiple watchers on the same stream MAY be executed in any order.
100109
*
110+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
111+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
112+
*
101113
* @param resource $stream The stream to monitor.
102114
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
103115
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -116,6 +128,9 @@ abstract public function onReadable($stream, callable $callback, $data = null);
116128
*
117129
* Multiple watchers on the same stream MAY be executed in any order.
118130
*
131+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
132+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
133+
*
119134
* @param resource $stream The stream to monitor.
120135
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
121136
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -133,6 +148,9 @@ abstract public function onWritable($stream, callable $callback, $data = null);
133148
*
134149
* Multiple watchers on the same signal MAY be executed in any order.
135150
*
151+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
152+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
153+
*
136154
* @param int $signo The signal number to monitor.
137155
* @param callable(string $watcherId, int $signo, mixed $data) $callback The callback to execute.
138156
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
@@ -144,7 +162,7 @@ abstract public function onWritable($stream, callable $callback, $data = null);
144162
abstract public function onSignal($signo, callable $callback, $data = null);
145163

146164
/**
147-
* Enable a watcher.
165+
* Enable a watcher to be active starting in the next tick.
148166
*
149167
* Watchers MUST immediately be marked as enabled, but only be activated (i.e. callbacks can be called) right before
150168
* the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
@@ -158,7 +176,10 @@ abstract public function onSignal($signo, callable $callback, $data = null);
158176
abstract public function enable($watcherId);
159177

160178
/**
161-
* Disable a watcher.
179+
* Disable a watcher immediately.
180+
*
181+
* A watcher MUST be disabled immediately, e.g. if a defer watcher disables a later defer watcher, the second defer
182+
* watcher isn't executed in this tick.
162183
*
163184
* Disabling a watcher MUST NOT invalidate the watcher. Calling this function MUST NOT fail, even if passed an
164185
* invalid watcher.

0 commit comments

Comments
 (0)