2016-12-30 02:16:04 +01:00
|
|
|
<?php
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2016-08-23 23:47:40 +02:00
|
|
|
namespace Amp\Parallel\Worker;
|
2016-08-18 18:04:48 +02:00
|
|
|
|
2017-03-16 23:03:59 +01:00
|
|
|
use Amp\Promise;
|
2015-08-27 16:10:08 +02:00
|
|
|
|
2015-12-05 06:50:32 +01:00
|
|
|
/**
|
|
|
|
* An interface for a parallel worker thread that runs a queue of tasks.
|
|
|
|
*/
|
2016-08-18 18:04:48 +02:00
|
|
|
interface Worker {
|
2015-08-27 16:10:08 +02:00
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Checks if the worker is running.
|
|
|
|
*
|
|
|
|
* @return bool True if the worker is running, otherwise false.
|
2015-08-27 16:10:08 +02:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function isRunning(): bool;
|
2015-08-27 16:10:08 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Checks if the worker is currently idle.
|
|
|
|
*
|
|
|
|
* @return bool
|
2015-08-27 16:10:08 +02:00
|
|
|
*/
|
2016-01-23 07:00:56 +01:00
|
|
|
public function isIdle(): bool;
|
2015-08-27 16:10:08 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Starts the context execution.
|
2015-08-27 16:10:08 +02:00
|
|
|
*/
|
2015-12-05 06:50:32 +01:00
|
|
|
public function start();
|
2015-08-27 16:10:08 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Enqueues a task to be executed by the worker.
|
|
|
|
*
|
|
|
|
* @param Task $task The task to enqueue.
|
|
|
|
*
|
2017-03-16 23:03:59 +01:00
|
|
|
* @return \Amp\Promise<mixed> Resolves with the return value of Task::run().
|
2015-08-27 16:10:08 +02:00
|
|
|
*/
|
2016-11-15 00:43:44 +01:00
|
|
|
public function enqueue(Task $task): Promise;
|
2015-08-27 16:10:08 +02:00
|
|
|
|
|
|
|
/**
|
2017-03-16 23:03:59 +01:00
|
|
|
* @return \Amp\Promise<int> Exit code.
|
2015-08-27 16:10:08 +02:00
|
|
|
*/
|
2016-11-15 00:43:44 +01:00
|
|
|
public function shutdown(): Promise;
|
2015-08-29 03:30:53 +02:00
|
|
|
|
|
|
|
/**
|
2015-12-05 06:50:32 +01:00
|
|
|
* Immediately kills the context.
|
2015-08-29 03:30:53 +02:00
|
|
|
*/
|
2015-12-05 06:50:32 +01:00
|
|
|
public function kill();
|
2015-08-29 03:30:53 +02:00
|
|
|
}
|