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