Initial commit

This commit is contained in:
Joop Schilder
2019-01-16 01:10:54 +01:00
commit a296fd61aa
5 changed files with 258 additions and 0 deletions

35
bin/app.php Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
// Create a function we want to run asynchronously
$process = function ($i) {
$delayMicroseconds = (10 - $i) * 1000000;
usleep($delayMicroseconds);
return getmypid();
};
// Execute the functions asynchronously - each returning a Promise
$promises = [];
foreach (range(0, 10) as $i)
$promises[] = Asynchronous::run($process, $i);
// Wait for all promises to resolve
while (count($promises) > 0) {
foreach ($promises as $index => $promise) {
if ($promise->isResolved() && !$promise->isEmpty()) {
print("Response retrieved: " . $promise->getValue() . PHP_EOL);
unset($promises[$index]);
}
}
}
exit(0);