|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Async sockets |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2015-2017, Efimov Evgenij <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the MIT license that is bundled |
|
8
|
|
|
* with this source code in the file LICENSE. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace AsyncSockets\Operation; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class DelayedOperation. Execution of this operation will be delayed until callable returns true. |
|
14
|
|
|
*/ |
|
15
|
|
|
class DelayedOperation implements OperationInterface |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Function to check whether operation is pending: |
|
19
|
|
|
* bool function(SocketInterface $socket, RequestExecutorInterface $executor) |
|
20
|
|
|
* |
|
21
|
|
|
* @var callable |
|
22
|
|
|
*/ |
|
23
|
|
|
private $callable; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Original operation |
|
27
|
|
|
* |
|
28
|
|
|
* @var OperationInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
private $origin; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Additional arguments to pass into callback |
|
34
|
|
|
* |
|
35
|
|
|
* @var array |
|
36
|
|
|
*/ |
|
37
|
|
|
private $arguments; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* DelayedOperation constructor. |
|
41
|
|
|
* |
|
42
|
|
|
* @param OperationInterface $origin Original operation which should be delayed |
|
43
|
|
|
* @param callable $callable Function to check whether operation is pending: |
|
44
|
|
|
* bool function(SocketInterface $socket, RequestExecutorInterface $executor, ...$arguments) |
|
45
|
|
|
* @param array $arguments Additional arguments to pass into callback |
|
46
|
|
|
*/ |
|
47
|
3 |
|
public function __construct(OperationInterface $origin, callable $callable, array $arguments = []) |
|
48
|
|
|
{ |
|
49
|
3 |
|
$this->origin = $origin; |
|
50
|
3 |
|
$this->callable = $callable; |
|
51
|
3 |
|
$this->arguments = $arguments; |
|
52
|
3 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** {@inheritdoc} */ |
|
55
|
1 |
|
public function getTypes() |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->origin->getTypes(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns function to invoke |
|
62
|
|
|
* |
|
63
|
|
|
* @return callable |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function getCallable() |
|
66
|
|
|
{ |
|
67
|
3 |
|
return $this->callable; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Return original operation to run after delay |
|
72
|
|
|
* |
|
73
|
|
|
* @return OperationInterface |
|
74
|
|
|
*/ |
|
75
|
2 |
|
public function getOriginalOperation() |
|
76
|
|
|
{ |
|
77
|
2 |
|
return $this->origin; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return additional arguments to pass into callback |
|
82
|
|
|
* |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function getArguments() |
|
86
|
|
|
{ |
|
87
|
3 |
|
return $this->arguments; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|