mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-04 11:02:29 +00:00
AsyncTask: Fix retrieval of null data from the thread-local storage (#6176)
This commit is contained in:
parent
bd65948453
commit
2420dee8be
@ -28,6 +28,7 @@ use pmmp\thread\Thread as NativeThread;
|
||||
use pmmp\thread\ThreadSafe;
|
||||
use pmmp\thread\ThreadSafeArray;
|
||||
use pocketmine\thread\NonThreadSafeValue;
|
||||
use function array_key_exists;
|
||||
use function assert;
|
||||
use function igbinary_serialize;
|
||||
use function igbinary_unserialize;
|
||||
@ -230,7 +231,7 @@ abstract class AsyncTask extends Runnable{
|
||||
*/
|
||||
protected function fetchLocal(string $key){
|
||||
$id = spl_object_id($this);
|
||||
if(!isset(self::$threadLocalStorage[$id][$key])){
|
||||
if(!isset(self::$threadLocalStorage[$id]) || !array_key_exists($key, self::$threadLocalStorage[$id])){
|
||||
throw new \InvalidArgumentException("No matching thread-local data found on this thread");
|
||||
}
|
||||
|
||||
|
@ -121,4 +121,23 @@ class AsyncPoolTest extends TestCase{
|
||||
usleep(50 * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
public function testNullComplexDataFetch() : void{
|
||||
$this->pool->submitTask(new class extends AsyncTask{
|
||||
public function __construct(){
|
||||
$this->storeLocal("null", null);
|
||||
}
|
||||
|
||||
public function onRun() : void{
|
||||
//dummy
|
||||
}
|
||||
|
||||
public function onCompletion() : void{
|
||||
AsyncPoolTest::assertNull($this->fetchLocal("null"));
|
||||
}
|
||||
});
|
||||
while($this->pool->collectTasks()){
|
||||
usleep(50 * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user