File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ final class GlobalLoop
12
12
private static $ factory ;
13
13
14
14
private static $ didRun = false ;
15
+ private static $ disableRunOnShutdown = false ;
15
16
16
17
public static function setFactory (callable $ factory = null )
17
18
{
@@ -24,6 +25,11 @@ public static function setFactory(callable $factory = null)
24
25
self ::$ factory = $ factory ;
25
26
}
26
27
28
+ public function disableRunOnShutdown ()
29
+ {
30
+ self ::$ disableRunOnShutdown = true ;
31
+ }
32
+
27
33
/**
28
34
* @return LoopInterface
29
35
*/
@@ -33,6 +39,14 @@ public static function get()
33
39
return self ::$ loop ;
34
40
}
35
41
42
+ register_shutdown_function (function () {
43
+ if (self ::$ disableRunOnShutdown || self ::$ didRun || !self ::$ loop ) {
44
+ return ;
45
+ }
46
+
47
+ self ::$ loop ->run ();
48
+ });
49
+
36
50
self ::$ loop = self ::create ();
37
51
38
52
self ::$ loop ->futureTick (function () {
You can’t perform that action at this time.
0 commit comments