mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 11:57:10 +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 */
|
||||
private static $instance = null;
|
||||
|
||||
/** @var \Threaded */
|
||||
/** @var \Threaded|null */
|
||||
private static $sleeper = null;
|
||||
|
||||
/** @var SleeperHandler */
|
||||
@ -1284,7 +1284,10 @@ class Server{
|
||||
* @return void
|
||||
*/
|
||||
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);
|
||||
}, $microseconds);
|
||||
}
|
||||
@ -1294,7 +1297,6 @@ class Server{
|
||||
throw new \InvalidStateException("Only one server instance can exist at once");
|
||||
}
|
||||
self::$instance = $this;
|
||||
self::$sleeper = new \Threaded;
|
||||
$this->tickSleeper = new SleeperHandler();
|
||||
$this->autoloader = $autoloader;
|
||||
$this->logger = $logger;
|
||||
|
Loading…
x
Reference in New Issue
Block a user