> */ private array $resolvers = []; private bool $firstHandlerCompleted = false; public function getName() : string{ return "Async Event Handler Priority Lock"; } public function getDescription() : string{ return "Tests that async events do not call handlers from the next priority until all promises from the current priority are resolved"; } public function run() : void{ HandlerListManager::global()->unregisterAll(); $main = $this->getPlugin(); $pluginManager = $main->getServer()->getPluginManager(); $pluginManager->registerAsyncEvent( GrandchildAsyncEvent::class, function(GrandchildAsyncEvent $event) use ($main) : Promise{ $resolver = new PromiseResolver(); $this->resolvers[] = $resolver; $resolver->getPromise()->onCompletion(function() : void{ $this->firstHandlerCompleted = true; }, function() use ($main) : void{ $main->getLogger()->error("Not expecting this to be rejected"); $this->setResult(Test::RESULT_ERROR); }); return $resolver->getPromise(); }, EventPriority::LOW, //anything below NORMAL is fine $main ); $pluginManager->registerAsyncEvent( GrandchildAsyncEvent::class, function(GrandchildAsyncEvent $event) use ($main) : ?Promise{ if(!$this->firstHandlerCompleted){ $main->getLogger()->error("This shouldn't run until the previous priority is done"); $this->setResult(Test::RESULT_FAILED); }else{ $this->setResult(Test::RESULT_OK); } return null; }, EventPriority::NORMAL, $main ); (new GrandchildAsyncEvent())->call(); } public function tick() : void{ foreach($this->resolvers as $k => $resolver){ $resolver->resolve(null); unset($this->resolvers[$k]); } } }