mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
As discussed in #2297: Honestly I don't see a fit purpose for async saving at all. It should either always be synchronous or always asynchronous, and at the user's own option. However, this isn't currently possible because Config doesn't enable you to get the serialized content without writing it to disk. Consider the following code: ```php for($i = 0, $size = $this->getServer()->getAsyncPool()->getSize(); $i < $size; ++$i){ $this->getServer()->getAsyncPool()->submitTask(new class extends AsyncTask{ public function onRun(){ sleep(5); } }); } $config = $this->getConfig(); $config->set("steve", "hi"); $config->save(true); $config->set("steve", "bye"); $config->save(false); ``` Output: ```yml --- steve: hi ... ``` Expected output: ```yml --- steve: bye ... ``` Additionally, if your configs are causing you performance issues when you're saving, it's a clear sign that a) you're saving too much b) you're abusing configs and should consider using a database. Configs should be used for _simple_ data which does not change much. Configuration is such that the _user_ is expected to be able to modify it. As such, it should never be an issue to save synchronously. In the future, something like ReactPHP may be introduced to allow proper async saving. When this happens, async saving would always be sequential but non blocking. Using threads for this makes no sense.