1
0
mirror of https://github.com/danog/parallel.git synced 2024-12-11 16:49:51 +01:00
parallel/lib/Worker/Worker.php

45 lines
903 B
PHP
Raw Normal View History

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
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.
*/
2018-10-07 16:50:45 +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
* 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().
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
/**
* @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
}