@@ -39,7 +39,9 @@ public static function execute(callable $callback, EventLoopDriver $driver)
39
39
*/
40
40
public static function get ()
41
41
{
42
- self ::inScope ();
42
+ if (null === self ::$ driver ) {
43
+ throw new \RuntimeException ('Not within the scope of an event loop driver ' );
44
+ }
43
45
44
46
return self ::$ driver ;
45
47
}
@@ -51,9 +53,7 @@ public static function get()
51
53
*/
52
54
public static function stop ()
53
55
{
54
- self ::inScope ();
55
-
56
- self ::$ driver ->stop ();
56
+ self ::get ()->stop ();
57
57
}
58
58
59
59
/**
@@ -65,9 +65,7 @@ public static function stop()
65
65
*/
66
66
public static function defer (callable $ callback )
67
67
{
68
- self ::inScope ();
69
-
70
- return self ::$ driver ->defer ($ callback );
68
+ return self ::get ()->defer ($ callback );
71
69
}
72
70
73
71
/**
@@ -80,9 +78,7 @@ public static function defer(callable $callback)
80
78
*/
81
79
public static function delay (callable $ callback , float $ time )
82
80
{
83
- self ::inScope ();
84
-
85
- return self ::$ driver ->delay ($ callback , $ time );
81
+ return self ::get ()->delay ($ callback , $ time );
86
82
}
87
83
88
84
/**
@@ -95,9 +91,7 @@ public static function delay(callable $callback, float $time)
95
91
*/
96
92
public static function repeat (callable $ callback , float $ interval )
97
93
{
98
- self ::inScope ();
99
-
100
- return self ::$ driver ->repeat ($ callback , $ interval );
94
+ return self ::get ()->repeat ($ callback , $ interval );
101
95
}
102
96
103
97
/**
@@ -110,9 +104,7 @@ public static function repeat(callable $callback, float $interval)
110
104
*/
111
105
public static function onReadable ($ stream , callable $ callback )
112
106
{
113
- self ::inScope ();
114
-
115
- return self ::$ driver ->onReadable ($ stream , $ callback );
107
+ return self ::get ()->onReadable ($ stream , $ callback );
116
108
}
117
109
118
110
/**
@@ -125,9 +117,7 @@ public static function onReadable($stream, callable $callback)
125
117
*/
126
118
public static function onWritable ($ stream , callable $ callback )
127
119
{
128
- self ::inScope ();
129
-
130
- return self ::$ driver ->onWritable ($ stream , $ callback );
120
+ return self ::get ()->onWritable ($ stream , $ callback );
131
121
}
132
122
133
123
/**
@@ -140,9 +130,7 @@ public static function onWritable($stream, callable $callback)
140
130
*/
141
131
public static function onSignal (int $ signo , callable $ callback )
142
132
{
143
- self ::inScope ();
144
-
145
- return self ::$ driver ->onSignal ($ signo , $ callback );
133
+ return self ::get ()->onSignal ($ signo , $ callback );
146
134
}
147
135
148
136
/**
@@ -154,9 +142,7 @@ public static function onSignal(int $signo, callable $callback)
154
142
*/
155
143
public static function onError (callable $ callback )
156
144
{
157
- self ::inScope ();
158
-
159
- return self ::$ driver ->onError ($ callback );
145
+ return self ::get ()->onError ($ callback );
160
146
}
161
147
162
148
/**
@@ -168,9 +154,7 @@ public static function onError(callable $callback)
168
154
*/
169
155
public static function enable (string $ eventIdentifier )
170
156
{
171
- self ::inScope ();
172
-
173
- self ::$ driver ->enable ($ eventIdentifier );
157
+ self ::get ()->enable ($ eventIdentifier );
174
158
}
175
159
176
160
/**
@@ -182,9 +166,7 @@ public static function enable(string $eventIdentifier)
182
166
*/
183
167
public static function disable (string $ eventIdentifier )
184
168
{
185
- self ::inScope ();
186
-
187
- self ::$ driver ->disable ($ eventIdentifier );
169
+ self ::get ()->disable ($ eventIdentifier );
188
170
}
189
171
190
172
/**
@@ -196,9 +178,7 @@ public static function disable(string $eventIdentifier)
196
178
*/
197
179
public static function cancel (string $ eventIdentifier )
198
180
{
199
- self ::inScope ();
200
-
201
- self ::$ driver ->cancel ($ eventIdentifier );
181
+ self ::get ()->cancel ($ eventIdentifier );
202
182
}
203
183
204
184
/**
@@ -212,9 +192,7 @@ public static function cancel(string $eventIdentifier)
212
192
*/
213
193
public static function reference (string $ eventIdentifier )
214
194
{
215
- self ::inScope ();
216
-
217
- self ::$ driver ->reference ($ eventIdentifier );
195
+ self ::get ()->reference ($ eventIdentifier );
218
196
}
219
197
220
198
/**
@@ -229,21 +207,7 @@ public static function reference(string $eventIdentifier)
229
207
*/
230
208
public static function unreference (string $ eventIdentifier )
231
209
{
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 );
247
211
}
248
212
249
213
/**
0 commit comments