File tree Expand file tree Collapse file tree 5 files changed +60
-4
lines changed Expand file tree Collapse file tree 5 files changed +60
-4
lines changed Original file line number Diff line number Diff line change @@ -30,18 +30,27 @@ public function __invoke(): Generator
30
30
foreach ($ configuredGenerators as $ configuredGenerator ) {
31
31
$ generatorConfig = $ configuredGenerator ->config ();
32
32
$ generatorConfig = $ this ->replaceTokens ($ generatorConfig , $ data );
33
- $ data = $ configuredGenerator ->generator ()->send ([$ generatorConfig , $ data ]);
33
+ $ response = $ configuredGenerator ->generator ()->send ([$ generatorConfig , $ data ]);
34
34
35
35
if (false === $ configuredGenerator ->generator ()->valid ()) {
36
36
break 2 ;
37
37
}
38
38
39
- if (false === is_array ($ data )) {
39
+ if (false === $ response instanceof Signal && false === is_array ($ response )) {
40
40
throw new InvalidYieldedValue (sprintf (
41
- 'All yielded values must bne arrays, got "%s" ' ,
41
+ 'All yielded values must be arrays or Signals , got "%s" ' ,
42
42
gettype ($ data )
43
43
));
44
44
}
45
+
46
+ if ($ response instanceof Signal) {
47
+ switch ($ response ) {
48
+ case Signal::continue ():
49
+ break 2 ;
50
+ }
51
+ }
52
+
53
+ $ data = $ response ;
45
54
}
46
55
47
56
yield $ data ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Core ;
4
+
5
+ final class Signal
6
+ {
7
+ private $ signal ;
8
+
9
+ private function __construct (string $ signal )
10
+ {
11
+ $ this ->signal = $ signal ;
12
+ }
13
+
14
+ public static function continue ()
15
+ {
16
+ return new self ('continue ' );
17
+ }
18
+ }
Original file line number Diff line number Diff line change 13
13
use PhpBench \Pipeline \Extension \Core \Stage \Filter \KeysFilter ;
14
14
use PhpBench \Pipeline \Extension \Core \Stage \Aggregator \DescribeAggregator ;
15
15
use PhpBench \Pipeline \Extension \Core \Stage \Parameter \CounterParameter ;
16
+ use PhpBench \Pipeline \Extension \Core \Stage \Valve \DelayValve ;
16
17
17
18
class CoreExtension implements PipelineExtension
18
19
{
@@ -32,6 +33,7 @@ public function __construct()
32
33
'parameter/counter ' => new CounterParameter (),
33
34
'sampler/callable ' => new CallableSampler (),
34
35
'sampler/curl ' => new CurlSampler (),
36
+ 'valve/delay ' => new DelayValve (),
35
37
'valve/take ' => new TakeValve (),
36
38
];
37
39
}
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ public function __invoke(): Generator
32
32
list ($ config , $ data ) = yield $ info ;
33
33
}
34
34
35
- yield Signal::continue ();
35
+ list ( $ config , $ data ) = yield Signal::continue ();
36
36
}
37
37
38
38
curl_multi_close ($ this ->multiHandle );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace PhpBench \Pipeline \Extension \Core \Stage \Valve ;
4
+
5
+ use PhpBench \Pipeline \Core \Stage ;
6
+ use Generator ;
7
+ use PhpBench \Pipeline \Core \Schema ;
8
+
9
+ class DelayValve implements Stage
10
+ {
11
+ public function __invoke (): Generator
12
+ {
13
+ list ($ config , $ data ) = yield ;
14
+
15
+ while (true ) {
16
+ usleep ($ config ['time ' ]);
17
+ list ($ config , $ data ) = yield $ data ;
18
+ }
19
+ }
20
+
21
+ public function configure (Schema $ schema )
22
+ {
23
+ $ schema ->setDefaults ([
24
+ 'time ' => 10000
25
+ ]);
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments