Vapm
  • About
    • Why is it called unblocking?
    • Next update?
    • Credit
    • Info
  • System
    • runEventLoop()
    • runSingleEventLoop()
    • setTimeout()
    • setInterval()
    • fetch()
    • read()
    • time() & timeEnd()
  • Asynchronous
    • getId()
    • await()
  • Promise
    • c()
    • getId()
    • getFiber()
    • isJustGetResult()
    • getTimeOut()
    • getTimeStart()
    • getTimeEnd()
    • setTimeEnd()
    • canDrop()
    • getStatus()
    • getResult()
    • getReturn()
    • getCallback()
    • resolve() & reject()
    • then() & catch() & finally()
    • useCallbacks()
    • all()
    • allSettled()
    • any()
    • race()
    • Some common methods
  • CoroutineGen
    • runBlocking()
    • runNonBlocking()
    • Deferred
    • Deferred Await All
    • repeat() & delay()
    • Channel
      • Example about Channel
    • AwaitGroup
      • Example
    • Mutex
      • Example
    • Goroutine vs CoroutineGen
      • Concurrency
  • Thread
    • How do I create a thread?
    • How do I share data between threads?
    • Advanced Thread
  • Worker
    • Example
  • Stream
    • read()
    • write()
    • append()
    • delete()
    • create()
    • overWrite()
  • FAQ
    • Why System::runEventLoop() and System::runSingleEventLoop() ?
    • Do you want concurrency?
  • PocketMine-PMMP
Powered by GitBook
On this page

Worker

Handle your jobs on the worker pool thread.

Work Interface

 /**
  * @param callable $work
  * @return void
  *
  * The work is a function that will be executed when the work is run.
  */
 public function add(callable $work): void;

 /**
  * @param int $index
  * @return void
  *
  * Remove the work from the work list.
  */
 public function remove(int $index): void;

 /**
  * @return void
  *
  * Remove all works from the work list.
  */
 public function clear(): void;

 /**
  * @return int
  *
  * Get the number of works in the work list.
  */
 public function count(): int;

 /**
  * @return bool
  *
  * Check if the work list is empty.
  */
 public function isEmpty(): bool;

 /**
  * @return mixed
  *
  * Get the first work in the work list.
  */
 public function dequeue(): mixed;

 /**
  * @param int $number
  * @return Generator
  *
  * Get the work list by number.
  */
 public function getArrayByNumber(int $number): Generator;

 /**
  * @return Generator
  *
  * Get all works in the work list.
  */
 public function getAll(): Generator;

 /**
  * @return void
  *
  * Run all works in the work list.
  */
 public function run(): void;

Worker Interface

 /**
  * @return bool
  *
  * Check the worker is started.
  */
 public function isStarted(): bool;

 /**
  * @return Work
  *
  * Get the work.
  */
 public function getWork(): Work;

 /**
  * @return void
  *
  * This is method help you to remove the worker from the worker list.
  * You should call this method when the work is done to avoid memory leaks.
  */
 public function done(): void;

 /**
  * @param mixed $result
  * @return void
  *
  * Collect the result of the work.
  */
 public function collect(mixed $result): void;

 /**
  * @return array<int|string, mixed>
  *
  * Get the result of the work.
  */
 public function get(): array;

 /**
  * @return bool
  *
  * Check the worker is locked.
  */
 public function isLocked(): bool;

 /**
  * @return void
  *
  * Lock the worker.
  */
 public function lock(): void;

 /**
  * @return void
  *
  * Unlock the worker.
  */
 public function unlock(): void;

 /**
  * @param Worker $worker
  * @param callable $callback
  * @return void
  *
  * Add a child worker to the parent worker.
  */
 public function addWorker(Worker $worker, callable $callback): void;

 /**
  * @return Async
  *
  * Run the work.
  * @throws Throwable
  */
 public function run(callable $callback): Async;
PreviousAdvanced ThreadNextExample

Last updated 9 months ago