Improve documentation of Thread and Worker

This commit is contained in:
Dylan K. Taylor 2021-09-10 15:57:45 +01:00
parent 32588d79c8
commit f5c9c02e09
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 16 additions and 2 deletions

View File

@ -23,10 +23,17 @@ declare(strict_types=1);
namespace pocketmine\thread;
use pocketmine\scheduler\AsyncTask;
use const PTHREADS_INHERIT_NONE;
/**
* This class must be extended by all custom threading classes
* Specialized Thread class aimed at PocketMine-MP-related usages. It handles setting up autoloading and error handling.
*
* Note: You probably don't need a thread unless you're doing something in it that's expected to last a long time (or
* indefinitely).
* For CPU-demanding tasks that take a short amount of time, consider using AsyncTasks instead to make better use of the
* CPU.
* @see AsyncTask
*/
abstract class Thread extends \Thread{
use CommonThreadPartsTrait;

View File

@ -26,7 +26,14 @@ namespace pocketmine\thread;
use const PTHREADS_INHERIT_NONE;
/**
* This class must be extended by all custom threading classes
* Specialized Worker class for PocketMine-MP-related use cases. It handles setting up autoloading and error handling.
*
* Workers are a special type of thread which execute tasks passed to them during their lifetime. Since creating a new
* thread has a high resource cost, workers can be kept around and reused for lots of short-lived tasks.
*
* As a plugin developer, you'll rarely (if ever) actually need to use this class directly.
* If you want to run tasks on other CPU cores, check out AsyncTask first.
* @see AsyncTask
*/
abstract class Worker extends \Worker{
use CommonThreadPartsTrait;