Total Complexity | 10 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class ParallelHandler implements ThreadInterface |
||
6 | { |
||
7 | protected $closure; |
||
8 | protected $runtime; |
||
9 | protected $future; |
||
10 | |||
11 | public function execute() |
||
12 | { |
||
13 | $fnArgs = func_get_args(); |
||
14 | |||
15 | $this->runtime = new \parallel\Runtime(); |
||
16 | $this->future = $this->runtime->run($this->closure, $fnArgs); |
||
17 | } |
||
18 | |||
19 | public function getResult() |
||
20 | { |
||
21 | return $this->future->value(); |
||
22 | } |
||
23 | |||
24 | public function stop($signal = SIGKILL, $wait = false) |
||
25 | { |
||
26 | $this->runtime->kill(); |
||
27 | } |
||
28 | |||
29 | public function isAlive() |
||
30 | { |
||
31 | return !$this->future->cancelled() && !$this->future->done(); |
||
32 | } |
||
33 | |||
34 | public function setClosure(\Closure $closure) |
||
35 | { |
||
36 | $this->closure = $closure; |
||
37 | } |
||
38 | |||
39 | public function waitFinish() |
||
40 | { |
||
41 | while (!$this->future->cancelled() && !$this->future->done()) { |
||
42 | sleep(1); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | public function getClassName() |
||
49 | } |
||
50 | } |