1 | <?php |
||
14 | class Attempt |
||
15 | { |
||
16 | /** |
||
17 | * @var integer |
||
18 | */ |
||
19 | private $current = 0; |
||
20 | |||
21 | /** |
||
22 | * @var integer |
||
23 | */ |
||
24 | private $step = 50; |
||
25 | |||
26 | /** |
||
27 | * timeout in milliseconds |
||
28 | * |
||
29 | * @var integer |
||
30 | */ |
||
31 | private $timeout = 2000; |
||
32 | |||
33 | /** |
||
34 | * @var callable |
||
35 | */ |
||
36 | private $callback; |
||
37 | |||
38 | /** |
||
39 | * @param callable $callback |
||
40 | */ |
||
41 | 1 | public function __construct(callable $callback) |
|
45 | |||
46 | /** |
||
47 | * @return callable |
||
48 | */ |
||
49 | 1 | public function getCallback() |
|
53 | |||
54 | /** |
||
55 | * @param integer $timeout |
||
56 | */ |
||
57 | 1 | public function setTimeout($timeout) |
|
63 | |||
64 | /** |
||
65 | * @return integer |
||
66 | */ |
||
67 | 1 | public function getTimeout() |
|
71 | |||
72 | /** |
||
73 | * @param integer $step |
||
74 | */ |
||
75 | 1 | public function setStep($step) |
|
81 | |||
82 | /** |
||
83 | * @return integer |
||
84 | */ |
||
85 | 1 | public function getStep() |
|
89 | |||
90 | /** |
||
91 | * @return integer |
||
92 | */ |
||
93 | 3 | public function getCurrent() |
|
97 | |||
98 | /** |
||
99 | * @return boolean |
||
100 | */ |
||
101 | 1 | public function hasTriesLeft() |
|
105 | |||
106 | /** |
||
107 | * @return integer |
||
108 | */ |
||
109 | 1 | public function getTries() |
|
113 | |||
114 | /** |
||
115 | * @return mixed |
||
116 | */ |
||
117 | 2 | public function execute() |
|
135 | |||
136 | /** |
||
137 | * Like normal execute, but throw RuntimeException on time out |
||
138 | * |
||
139 | * @param string $message optional message |
||
140 | * @throws RuntimeException on time out |
||
141 | * @return mixed |
||
142 | */ |
||
143 | 2 | public function executeOrFail($message = 'Timed out attempting to execute callback') |
|
153 | } |
||
154 |