mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 04:17:07 +00:00
Server: Lazy-init static sleeper as-needed
this makes it testable without a server context.
This commit is contained in:
parent
8cba2e0346
commit
ecf662bf74
@ -186,7 +186,7 @@ class Server{
|
|||||||
/** @var Server */
|
/** @var Server */
|
||||||
private static $instance = null;
|
private static $instance = null;
|
||||||
|
|
||||||
/** @var \Threaded */
|
/** @var \Threaded|null */
|
||||||
private static $sleeper = null;
|
private static $sleeper = null;
|
||||||
|
|
||||||
/** @var SleeperHandler */
|
/** @var SleeperHandler */
|
||||||
@ -1284,7 +1284,10 @@ class Server{
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function microSleep(int $microseconds){
|
public static function microSleep(int $microseconds){
|
||||||
Server::$sleeper->synchronized(function(int $ms) : void{
|
if(self::$sleeper === null){
|
||||||
|
self::$sleeper = new \Threaded();
|
||||||
|
}
|
||||||
|
self::$sleeper->synchronized(function(int $ms) : void{
|
||||||
Server::$sleeper->wait($ms);
|
Server::$sleeper->wait($ms);
|
||||||
}, $microseconds);
|
}, $microseconds);
|
||||||
}
|
}
|
||||||
@ -1294,7 +1297,6 @@ class Server{
|
|||||||
throw new \InvalidStateException("Only one server instance can exist at once");
|
throw new \InvalidStateException("Only one server instance can exist at once");
|
||||||
}
|
}
|
||||||
self::$instance = $this;
|
self::$instance = $this;
|
||||||
self::$sleeper = new \Threaded;
|
|
||||||
$this->tickSleeper = new SleeperHandler();
|
$this->tickSleeper = new SleeperHandler();
|
||||||
$this->autoloader = $autoloader;
|
$this->autoloader = $autoloader;
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user