mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-03 00:25:04 +00:00
AsyncTask::setResult(): permit returning ThreadSafe objects to the main thread
this is now supported thanks to the object rescue feature implemented in pthreads 5.1, making returning of thread-safe values from async tasks possible. This needs to be explicitly supported, since otherwise it will attempt to serialize them, which isn't supported anymore.
This commit is contained in:
@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
namespace pocketmine\scheduler;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use pmmp\thread\ThreadSafeArray;
|
||||
use pocketmine\promise\PromiseResolver;
|
||||
use pocketmine\snooze\SleeperHandler;
|
||||
use pocketmine\utils\MainLogger;
|
||||
use function define;
|
||||
@ -69,4 +71,21 @@ class AsyncPoolTest extends TestCase{
|
||||
}
|
||||
self::assertTrue(PublishProgressRaceAsyncTask::$success, "Progress was not reported before task completion");
|
||||
}
|
||||
|
||||
public function testThreadSafeSetResult() : void{
|
||||
$resolver = new PromiseResolver();
|
||||
$resolver->getPromise()->onCompletion(
|
||||
function(ThreadSafeArray $result) : void{
|
||||
self::assertCount(1, $result);
|
||||
self::assertSame(["foo"], (array) $result);
|
||||
},
|
||||
function() : void{
|
||||
self::fail("Promise failed");
|
||||
}
|
||||
);
|
||||
$this->pool->submitTask(new ThreadSafeResultAsyncTask($resolver));
|
||||
while($this->pool->collectTasks()){
|
||||
usleep(50 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user