Skip to content

Commit 624060c

Browse files
Removed inScope()
1 parent 71fcb29 commit 624060c

File tree

1 file changed

+16
-52
lines changed

1 file changed

+16
-52
lines changed

src/EventLoop.php

Lines changed: 16 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public static function execute(callable $callback, EventLoopDriver $driver)
3939
*/
4040
public static function get()
4141
{
42-
self::inScope();
42+
if (null === self::$driver) {
43+
throw new \RuntimeException('Not within the scope of an event loop driver');
44+
}
4345

4446
return self::$driver;
4547
}
@@ -51,9 +53,7 @@ public static function get()
5153
*/
5254
public static function stop()
5355
{
54-
self::inScope();
55-
56-
self::$driver->stop();
56+
self::get()->stop();
5757
}
5858

5959
/**
@@ -65,9 +65,7 @@ public static function stop()
6565
*/
6666
public static function defer(callable $callback)
6767
{
68-
self::inScope();
69-
70-
return self::$driver->defer($callback);
68+
return self::get()->defer($callback);
7169
}
7270

7371
/**
@@ -80,9 +78,7 @@ public static function defer(callable $callback)
8078
*/
8179
public static function delay(callable $callback, float $time)
8280
{
83-
self::inScope();
84-
85-
return self::$driver->delay($callback, $time);
81+
return self::get()->delay($callback, $time);
8682
}
8783

8884
/**
@@ -95,9 +91,7 @@ public static function delay(callable $callback, float $time)
9591
*/
9692
public static function repeat(callable $callback, float $interval)
9793
{
98-
self::inScope();
99-
100-
return self::$driver->repeat($callback, $interval);
94+
return self::get()->repeat($callback, $interval);
10195
}
10296

10397
/**
@@ -110,9 +104,7 @@ public static function repeat(callable $callback, float $interval)
110104
*/
111105
public static function onReadable($stream, callable $callback)
112106
{
113-
self::inScope();
114-
115-
return self::$driver->onReadable($stream, $callback);
107+
return self::get()->onReadable($stream, $callback);
116108
}
117109

118110
/**
@@ -125,9 +117,7 @@ public static function onReadable($stream, callable $callback)
125117
*/
126118
public static function onWritable($stream, callable $callback)
127119
{
128-
self::inScope();
129-
130-
return self::$driver->onWritable($stream, $callback);
120+
return self::get()->onWritable($stream, $callback);
131121
}
132122

133123
/**
@@ -140,9 +130,7 @@ public static function onWritable($stream, callable $callback)
140130
*/
141131
public static function onSignal(int $signo, callable $callback)
142132
{
143-
self::inScope();
144-
145-
return self::$driver->onSignal($signo, $callback);
133+
return self::get()->onSignal($signo, $callback);
146134
}
147135

148136
/**
@@ -154,9 +142,7 @@ public static function onSignal(int $signo, callable $callback)
154142
*/
155143
public static function onError(callable $callback)
156144
{
157-
self::inScope();
158-
159-
return self::$driver->onError($callback);
145+
return self::get()->onError($callback);
160146
}
161147

162148
/**
@@ -168,9 +154,7 @@ public static function onError(callable $callback)
168154
*/
169155
public static function enable(string $eventIdentifier)
170156
{
171-
self::inScope();
172-
173-
self::$driver->enable($eventIdentifier);
157+
self::get()->enable($eventIdentifier);
174158
}
175159

176160
/**
@@ -182,9 +166,7 @@ public static function enable(string $eventIdentifier)
182166
*/
183167
public static function disable(string $eventIdentifier)
184168
{
185-
self::inScope();
186-
187-
self::$driver->disable($eventIdentifier);
169+
self::get()->disable($eventIdentifier);
188170
}
189171

190172
/**
@@ -196,9 +178,7 @@ public static function disable(string $eventIdentifier)
196178
*/
197179
public static function cancel(string $eventIdentifier)
198180
{
199-
self::inScope();
200-
201-
self::$driver->cancel($eventIdentifier);
181+
self::get()->cancel($eventIdentifier);
202182
}
203183

204184
/**
@@ -212,9 +192,7 @@ public static function cancel(string $eventIdentifier)
212192
*/
213193
public static function reference(string $eventIdentifier)
214194
{
215-
self::inScope();
216-
217-
self::$driver->reference($eventIdentifier);
195+
self::get()->reference($eventIdentifier);
218196
}
219197

220198
/**
@@ -229,21 +207,7 @@ public static function reference(string $eventIdentifier)
229207
*/
230208
public static function unreference(string $eventIdentifier)
231209
{
232-
self::inScope();
233-
234-
self::$driver->unreference($eventIdentifier);
235-
}
236-
237-
/**
238-
* Validate that the event loop is currently within the scope of a driver.
239-
*
240-
* @return void
241-
*/
242-
private static function inScope()
243-
{
244-
if (null === self::$driver) {
245-
throw new \RuntimeException('Not within the scope of an event loop driver');
246-
}
210+
self::get()->unreference($eventIdentifier);
247211
}
248212

249213
/**

0 commit comments

Comments
 (0)