mirror of
https://github.com/danog/parallel.git
synced 2024-12-12 09:09:35 +01:00
312aecf1ff
The context can automatically be started when a job is enqueued.
44 lines
903 B
PHP
44 lines
903 B
PHP
<?php
|
|
|
|
namespace Amp\Parallel\Worker;
|
|
|
|
use Amp\Promise;
|
|
|
|
/**
|
|
* An interface for a parallel worker thread that runs a queue of tasks.
|
|
*/
|
|
interface Worker {
|
|
/**
|
|
* Checks if the worker is running.
|
|
*
|
|
* @return bool True if the worker is running, otherwise false.
|
|
*/
|
|
public function isRunning(): bool;
|
|
|
|
/**
|
|
* Checks if the worker is currently idle.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isIdle(): bool;
|
|
|
|
/**
|
|
* Enqueues a task to be executed by the worker.
|
|
*
|
|
* @param Task $task The task to enqueue.
|
|
*
|
|
* @return \Amp\Promise<mixed> Resolves with the return value of Task::run().
|
|
*/
|
|
public function enqueue(Task $task): Promise;
|
|
|
|
/**
|
|
* @return \Amp\Promise<int> Exit code.
|
|
*/
|
|
public function shutdown(): Promise;
|
|
|
|
/**
|
|
* Immediately kills the context.
|
|
*/
|
|
public function kill();
|
|
}
|