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
1212 private static $ factory ;
1313
1414 private static $ didRun = false ;
15+ private static $ disableRunOnShutdown = false ;
1516
1617 public static function setFactory (callable $ factory = null )
1718 {
@@ -24,6 +25,11 @@ public static function setFactory(callable $factory = null)
2425 self ::$ factory = $ factory ;
2526 }
2627
28+ public function disableRunOnShutdown ()
29+ {
30+ self ::$ disableRunOnShutdown = true ;
31+ }
32+
2733 /**
2834 * @return LoopInterface
2935 */
@@ -33,6 +39,14 @@ public static function get()
3339 return self ::$ loop ;
3440 }
3541
42+ register_shutdown_function (function () {
43+ if (self ::$ disableRunOnShutdown || self ::$ didRun || !self ::$ loop ) {
44+ return ;
45+ }
46+
47+ self ::$ loop ->run ();
48+ });
49+
3650 self ::$ loop = self ::create ();
3751
3852 self ::$ loop ->futureTick (function () {
You can’t perform that action at this time.
0 commit comments