Skip to content

Commit

Permalink
Improve async example
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Dec 12, 2021
1 parent 1a08690 commit e44a190
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions examples/async.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,40 @@

require __DIR__ . '/../vendor/autoload.php';

use Amp\Future;
use function Amp\async;
use function Amp\delay;

$future1 = async(function () {
delay(1);

print 'b';
print 'c';
});

$future2 = async(function () {
delay(2);

print 'c';
print 'd';
});

$future3 = async(function () {
delay(0.5);

print 'a';
});

$future4 = async(function () {
Future::complete()->await();

print 'b';
});

$future1->await();
$future2->await();
$future3->await();

delay(1);

print 'd';
print 'e';

delay(1);

print 'e';
print 'f';

0 comments on commit e44a190

Please sign in to comment.