diff --git a/src/Loop.php b/src/Loop.php index 76f54d3..0d7d303 100644 --- a/src/Loop.php +++ b/src/Loop.php @@ -43,7 +43,7 @@ final class Loop public static function setFactory(DriverFactory $factory = null) { if (self::$level > 0) { - throw new \RuntimeException("Setting a new factory while running isn't allowed!"); + throw new \RuntimeException("Setting a new factory while running isn't allowed."); } self::$factory = $factory; @@ -82,6 +82,27 @@ public static function execute(callable $callback, Driver $driver = null) } } + /** + * Run an unscoped loop. + * + * When possible, execute() SHOULD be preferred over run() for more explicit scoping. + * + * @return void + * + * @see \AsyncInterop\Loop\Driver::run() + */ + public static function run() + { + $driver = self::$driver ?: self::get(); + self::$level++; + + try { + $driver->run(); + } finally { + self::$level--; + } + } + /** * Create a new driver if a factory is present, otherwise throw. *