Ejemplo n.º 1
0
 /**
  * Instantiate and return a presenter wrapping the passed object.
  *
  * @param Presentable|mixed $object
  * @param string            $presenter [optional]
  *
  * @return Presenter
  */
 function present($object, $with = 'presenter')
 {
     if ($object instanceof Presenter && !$object instanceof Presentable) {
         return $object;
     }
     return produce($object, $with);
 }
Ejemplo n.º 2
0
function pidigits($N)
{
    $k = 1;
    $n1 = gmp_init(4);
    $n2 = gmp_init(3);
    $d = gmp_init(1);
    $i = 0;
    while ($i < $N) {
        $y = digit($n1, $n2, $d);
        if ($y !== false) {
            echo gmp_strval($y);
            $i++;
            if ($i % 10 == 0) {
                echo "\t:", $i, "\n";
            }
            extractd($n1, $n2, $d, $y);
        } else {
            produce($n1, $n2, $d, $k);
            $k++;
        }
    }
    if ($i % 10 != 0) {
        echo str_repeat(' ', 10 - $N % 10), "\t:", $N, "\n";
    }
}
Ejemplo n.º 3
0
function main()
{
    if (!isset($_SERVER['argv'][1])) {
        die('You must provide an argument of either "consume" or "produce"');
    }
    if ($_SERVER['argv'][1] == 'produce') {
        produce();
    }
    if ($_SERVER['argv'][1] == 'consume') {
        consume();
    }
}
Ejemplo n.º 4
0
 /**
  * Instantiate and return a resolvable wrapping the passed object.
  *
  * @param Producer|mixed $object
  * @param string $what
  *
  * @return Producible
  */
 function produce($object, $what)
 {
     $collection = null;
     if ($object instanceof Collection) {
         $collection = $object->all();
     } elseif (is_array($object)) {
         $collection = $object;
     }
     if (!is_null($collection)) {
         $objects = [];
         foreach ($collection as $item) {
             $objects[] = produce($item, $what);
         }
         if ($object instanceof Collection) {
             return new Collection($objects);
         }
         return $objects;
     }
     return $object->produce($what);
 }
Ejemplo n.º 5
0
}
// $gen = gen();
// $ret = $gen->current();
// echo "[main]", $ret, "\n";
// $ret = $gen->send("send1");
// echo "[main]", $ret, "\n";
// $ret = $gen->send("send2");
// echo "[main]", $ret, "\n";
function consumer()
{
    $response = '';
    while (true) {
        $result = (yield $response);
        var_dump("[CONSUMER] Consuming {$result}...");
        $response = '200 OK';
    }
}
function produce($c_instance)
{
    $num = 0;
    while ($num < 5) {
        $num = $num + 1;
        var_dump("[PRODUCER] Producing {$num}...");
        sleep(3);
        $response = $c_instance->send($num);
        var_dump("[PRODUCER] Consumer return: {$response}");
    }
}
$c = consumer();
produce($c);