-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
I found an issue with Await::safeRace()
This is probably a philosophical issue regarding the race, as it only occurs in safeRace
Maybe we need exceptions for these bad codes
Note: I discovered this by my mistake
workaround
Catch RaceLostException. Do Not implement race lose yourself
code
<?php
declare(strict_types=1);
namespace daisukedaisuke\test;
use SOFe\AwaitGenerator\Await;
class test{
private $list = [];
public function __construct(){
$this->init();
}
public function init() : void{
$this->race($this->rateChild(0), $this->rateChild(1), $this->rateChild(2));
$this->reject(0, new \RuntimeException());
$this->reject(1, new \RuntimeException());
$this->solve(2, "happy!");//Here is where the exception occurs
}
public function rateChild(int $id) : \Generator{
yield from $this->solver($id);
}
public function solver(int $id) : \Generator{
//This is where the problem occurs
try{
yield from Await::promise(function(\Closure $resolve, \Closure $reject) use ($id){
$this->list[$id] = [$resolve, $reject];
});
}catch(\RuntimeException $throwable){
var_dump("!!");//Squash exceptions!!!
}
}
/**
* @param array<\Generator<mixed>> $array
* @throws \Throwable
*/
public function race(\Generator ...$array) : void{
Await::g2c(Await::safeRace($array));
}
public function reject(int $id, \Throwable $throwable) : void{
[$resolve, $reject] = $this->list[$id];
($reject)($throwable);
}
public function solve(int $id, mixed $text) : void{
[$resolve, $reject] = $this->list[$id];
($resolve)($text);
}
}
exception
The reason for using the ModuleLoader plugin is for development environments that change frequently
For the production server I will remove the moduleloader and build using Pharynx, creating a single portal phar and auto loader
[05:08:41.813] [Server thread/CRITICAL]: Exception: "Cannot get return value of a generator that hasn't returned" (EXCEPTION) in "plugins/ModuleLoader/src/SOFe/AwaitGenerator/Await" at line 344
--- Stack trace ---
#0 plugins/ModuleLoader/src/SOFe/AwaitGenerator/Await(344): Generator->getReturn()
#1 plugins/ModuleLoader/src/SOFe/AwaitGenerator/Await(321): SOFe\AwaitGenerator\Await->wakeup(object Closure#72457)
#2 plugins/ModuleLoader/src/SOFe/AwaitGenerator/Await(561): SOFe\AwaitGenerator\Await->wakeupFlat(object Closure#72457)
#3 plugins/ModuleLoader/src/SOFe/AwaitGenerator/AwaitChild(52): SOFe\AwaitGenerator\Await->recheckPromiseQueue(object SOFe\AwaitGenerator\AwaitChild#72510)
#4 plugins/test/src/daisukedaisuke/test/test(55): SOFe\AwaitGenerator\AwaitChild->resolve(string[6] happy!)
#5 plugins/test/src/daisukedaisuke/test/test(19): daisukedaisuke\test\test->solve(int 2, string[6] happy!)
#6 plugins/test/src/daisukedaisuke/test/test(12): daisukedaisuke\test\test->init()
#7 plugins/test/src/daisukedaisuke/test/Main(24): daisukedaisuke\test\test->__construct()
#8 pmsrc/src/plugin/PluginBase(119): daisukedaisuke\test\Main->onEnable()
#9 pmsrc/src/plugin/PluginManager(461): pocketmine\plugin\PluginBase->onEnableStateChange(true)
#10 pmsrc/src/Server(1446): pocketmine\plugin\PluginManager->enablePlugin(object daisukedaisuke\test\Main#62090)
#11 pmsrc/src/Server(1073): pocketmine\Server->enablePlugins(object pocketmine\plugin\PluginEnableOrder#62047)
#12 pmsrc/src/PocketMine(360): pocketmine\Server->__construct(object pocketmine\thread\ThreadSafeClassLoader#6, object pocketmine\utils\MainLogger#3, string[13] P:\ikou\play\, string[21] P:\ikou\play\plugins\)
#13 pmsrc/src/PocketMine(383): pocketmine\server()
--- End of exception information ---
Metadata
Metadata
Assignees
Labels
No labels