Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce6f2a8

Browse files
keluniktrowski
authored andcommitted
Add note about watchers being enabled by default to every method creating a watcher
1 parent 82c05ab commit ce6f2a8

File tree

2 files changed

+50
-8
lines changed

2 files changed

+50
-8
lines changed

src/Loop.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ public static function stop()
148148
/**
149149
* Defer the execution of a callback.
150150
*
151-
* The deferred callable MUST be executed in the next tick of the event loop and before any other type of watcher.
152-
* Order of enabling MUST be preserved when executing the callbacks.
151+
* The deferred callable MUST be executed before any other type of watcher in a tick. Order of enabling MUST be
152+
* preserved when executing the callbacks.
153+
*
154+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
155+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
153156
*
154157
* @param callable(string $watcherId, mixed $data) $callback The callback to defer. The `$watcherId` will be
155158
* invalidated before the callback call.
@@ -169,6 +172,9 @@ public static function defer(callable $callback, $data = null)
169172
* The delay is a minimum and approximate, accuracy is not guaranteed. Order of calls MUST be determined by which
170173
* timers expire first, but timers with the same expiration time MAY be executed in any order.
171174
*
175+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
176+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
177+
*
172178
* @param int $delay The amount of time, in milliseconds, to delay the execution for.
173179
* @param callable(string $watcherId, mixed $data) $callback The callback to delay. The `$watcherId` will be
174180
* invalidated before the callback call.
@@ -189,6 +195,9 @@ public static function delay($time, callable $callback, $data = null)
189195
* determined by which timers expire first, but timers with the same expiration time MAY be executed in any order.
190196
* The first execution is scheduled after the first interval period.
191197
*
198+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
199+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
200+
*
192201
* @param int $interval The time interval, in milliseconds, to wait between executions.
193202
* @param callable(string $watcherId, mixed $data) $callback The callback to repeat.
194203
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -211,6 +220,9 @@ public static function repeat($interval, callable $callback, $data = null)
211220
*
212221
* Multiple watchers on the same stream MAY be executed in any order.
213222
*
223+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
224+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
225+
*
214226
* @param resource $stream The stream to monitor.
215227
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
216228
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -233,6 +245,9 @@ public static function onReadable($stream, callable $callback, $data = null)
233245
*
234246
* Multiple watchers on the same stream MAY be executed in any order.
235247
*
248+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
249+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
250+
*
236251
* @param resource $stream The stream to monitor.
237252
* @param callable(string $watcherId, resource $stream, mixed $data) $callback The callback to execute.
238253
* @param mixed $data Arbitrary data given to the callback function as the `$data` parameter.
@@ -254,6 +269,9 @@ public static function onWritable($stream, callable $callback, $data = null)
254269
*
255270
* Multiple watchers on the same signal MAY be executed in any order.
256271
*
272+
* The created watcher MUST immediately be marked as enabled, but only be activated (i.e. callback can be called)
273+
* right before the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
274+
*
257275
* @param int $signo The signal number to monitor.
258276
* @param callable(string $watcherId, int $signo, mixed $data) $callback The callback to execute.
259277
* @param mixed $data Arbitrary data given to the callback function as the $data parameter.
@@ -269,7 +287,7 @@ public static function onSignal($signo, callable $callback, $data = null)
269287
}
270288

271289
/**
272-
* Enable a watcher.
290+
* Enable a watcher to be active starting in the next tick.
273291
*
274292
* Watchers MUST immediately be marked as enabled, but only be activated (i.e. callbacks can be called) right before
275293
* the next tick. Callbacks of watchers MUST NOT be called in the tick they were enabled.
@@ -287,7 +305,10 @@ public static function enable($watcherId)
287305
}
288306

289307
/**
290-
* Disable a watcher.
308+
* Disable a watcher immediately.
309+
*
310+
* A watcher MUST be disabled immediately, e.g. if a defer watcher disables a later defer watcher, the second defer
311+
* watcher isn't executed in this tick.
291312
*
292313
* Disabling a watcher MUST NOT invalidate the watcher. Calling this function MUST NOT fail, even if passed an
293314
* invalid watcher.

src/Loop/Driver.php

Lines changed: 25 additions & 4 deletions
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)