1 | <?php |
||
19 | class Thread implements ThreadInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var ThreadInterface |
||
23 | */ |
||
24 | private $threadInstance = null; |
||
25 | |||
26 | /** |
||
27 | * constructor method |
||
28 | * |
||
29 | * @param mixed $callable string with the function name or a array with the instance and the method name |
||
30 | * @throws RuntimeException |
||
31 | * @throws InvalidArgumentException |
||
32 | */ |
||
33 | public function __construct(callable $callable) |
||
37 | |||
38 | /** |
||
39 | * @return ThreadInterface |
||
40 | */ |
||
41 | public function getThreadInstance() |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Start the thread |
||
61 | * |
||
62 | * @throws RuntimeException |
||
63 | */ |
||
64 | public function execute() |
||
69 | |||
70 | /** |
||
71 | * Get the thread result from the shared memory block and erase it |
||
72 | * |
||
73 | * @return mixed |
||
74 | */ |
||
75 | public function getResult() |
||
79 | |||
80 | /** |
||
81 | * Kill a thread |
||
82 | * |
||
83 | * @param int $signal |
||
84 | * @param bool $wait |
||
85 | */ |
||
86 | public function stop($signal = SIGKILL, $wait = false) |
||
90 | |||
91 | /** |
||
92 | * Check if the forked process is alive |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function isAlive() |
||
99 | |||
100 | public function waitFinish() |
||
104 | |||
105 | /** |
||
106 | * Set the thread callable method |
||
107 | * @param callable $callable |
||
108 | * @return mixed |
||
109 | */ |
||
110 | public function setCallable(callable $callable) |
||
114 | } |
||
115 |