Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
test | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
handle | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace App\Console\Commands; |
4 | |
5 | use Illuminate\Console\Command; |
6 | use Amp\Future; |
7 | use function Amp\async; |
8 | use function Amp\delay; |
9 | |
10 | class test extends Command |
11 | { |
12 | /** |
13 | * The name and signature of the console command. |
14 | * |
15 | * @var string |
16 | */ |
17 | protected $signature = 'command:name'; |
18 | |
19 | /** |
20 | * The console command description. |
21 | * |
22 | * @var string |
23 | */ |
24 | protected $description = 'Command description'; |
25 | |
26 | /** |
27 | * Execute the console command. |
28 | * |
29 | * @return int |
30 | */ |
31 | public function handle() |
32 | { |
33 | var_dump(config('app.var1')); |
34 | $future1 = async(function () { |
35 | echo 'Hello '; |
36 | |
37 | // delay() is a non-blocking version of PHP's sleep() function, |
38 | // which only pauses the current fiber instead of blocking the whole process. |
39 | delay(2); |
40 | |
41 | echo 'the future! '; |
42 | }); |
43 | |
44 | $future2 = async(function () { |
45 | echo 'World '; |
46 | |
47 | // Let's pause for only 1 instead of 2 seconds here, |
48 | // so our text is printed in the correct order. |
49 | delay(1); |
50 | |
51 | echo 'from '; |
52 | }); |
53 | |
54 | // Our functions have been queued, but won't be executed until the event-loop gains control. |
55 | echo "Let's start: "; |
56 | |
57 | // Awaiting a future outside a fiber switches to the event loop until the future is complete. |
58 | // Once the event loop gains control, it executes our already queued functions we've passed to async() |
59 | $future1->await(); |
60 | $future2->await(); |
61 | |
62 | echo PHP_EOL; |
63 | return Command::SUCCESS; |
64 | } |
65 | } |