-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGenericLoop.php
More file actions
31 lines (27 loc) · 723 Bytes
/
GenericLoop.php
File metadata and controls
31 lines (27 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php declare(strict_types=1);
require 'vendor/autoload.php';
use danog\Loop\GenericLoop;
use function Amp\delay;
/** @var GenericLoop[] */
$loops = [];
for ($x = 0; $x < 10; $x++) {
$callable = function (GenericLoop $loop): float {
static $number = 0;
echo "$loop: $number".PHP_EOL;
$number++;
return $number < 10 ? 1.0 : GenericLoop::STOP;
};
$loop = new GenericLoop($callable, "Loop number $x");
$loop->start();
delay(0.1);
$loops []= $loop;
}
delay(5);
echo "Resuming prematurely all loops!".PHP_EOL;
foreach ($loops as $loop) {
$loop->resume();
}
echo "OK done, waiting 5 more seconds!".PHP_EOL;
delay(5);
echo "Closing all loops!".PHP_EOL;
delay(0.01);