Removed bin

This commit is contained in:
Joop Schilder 2019-01-16 16:39:33 +01:00
parent 476eb141b8
commit 78fdbfaa49
4 changed files with 0 additions and 110 deletions

View File

@ -1,44 +0,0 @@
#!/usr/bin/php
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use function Joop\Asynchronous\async;
use Joop\Asynchronous\Promise;
/**
* @param Promise[] $promises
*/
function awaitPromises(array &$promises)
{
foreach ($promises as $index => $promise) {
if ($promise->isResolved()) {
unset($promises[$index]);
if (!$promise->isEmpty() && !$promise->isError())
print($promise->getValue() . PHP_EOL);
}
}
}
/*
* Example of asynchronous processing in PHP
*/
$process = function ($i) {
$delayMicroseconds = (5 - $i) * 1000000;
usleep($delayMicroseconds);
return sprintf(
'PID %-5d slept for %.1f seconds',
getmypid(), $delayMicroseconds / 1000000
);
};
$promises = [];
foreach (range(0, 5) as $i)
$promises[] = async($process, $i);
while (count($promises) > 0)
awaitPromises($promises);

View File

@ -1,15 +0,0 @@
#!/usr/bin/php
<?php
use function Joop\Asynchronous\async;
require_once __DIR__ . '/../../vendor/autoload.php';
$promise = async(function () {
sleep(1);
return range(random_int(0, 10), random_int(20, 60));
});
$array = $promise->resolve()->getValue();
var_dump($array);

View File

@ -1,37 +0,0 @@
#!/usr/bin/php
<?php
use function Joop\Asynchronous\async;
require_once __DIR__ . '/../../vendor/autoload.php';
// Example class
class Sample
{
private $data;
public function __construct()
{
$this->data = [1, 2, 3];
}
public function getData()
{
return $this->data;
}
}
// Create the process
$promise = async(function () {
sleep(2);
return new Sample();
});
// We can do some other stuff here while the process is running
// Resolve the promise
/** @var Sample $sample */
$sample = $promise->resolve()->getValue();
var_dump($sample->getData());

View File

@ -1,14 +0,0 @@
#!/usr/bin/php
<?php
use function Joop\Asynchronous\async;
require_once __DIR__ . '/../../vendor/autoload.php';
$process = function ($number) {
sleep($number);
return $number;
};
async($process, 2);
// Do stuff...