Esempio n. 1
0
<?php

include 'Task.php';
function task1()
{
    for ($i = 1; $i <= 10; ++$i) {
        echo "This is task 1 iternation {$i}.\n";
        yield;
    }
}
$task = new Task(1, task1());
$task->run();
Esempio n. 2
0
function task1()
{
    echo "#################################################\n";
    echo "# Update Mediboard SVN and user-oriented logger #\n";
    echo "#################################################\n\n";
    echo "Action to perform:\n\n";
    echo "[1] Show the update log\n";
    echo "[2] Perform the actual update\n";
    echo "--------------------------------\n";
    echo "[0] Return to main menu\n";
    echo "\nSelected action: ";
    $action = trim(fgets(STDIN));
    switch ($action) {
        case "1":
            $action = "info";
            break;
        case "2":
            $action = "real";
            break;
        case "0":
            echo exec("clear") . "\n";
            menu();
            break;
        default:
            echo exec("clear") . "\n";
            echo "Incorrect input\n";
            task1();
    }
    echo "\nRevision number [default HEAD]: ";
    $revision = trim(fgets(STDIN));
    switch ($revision) {
        case "":
            echo shell_exec("sh " . $GLOBALS['currentDir'] . "/update.sh " . $action) . "\n\n";
            menu();
            break;
        default:
            echo shell_exec("sh " . $GLOBALS['currentDir'] . "/update.sh " . $action . " -r " . $revision) . "\n\n";
            menu();
    }
}
Esempio n. 3
0
<?php

include_once 'Task.php';
include_once 'Scheduler.php';
function task1()
{
    for ($i = 1; $i <= 10; ++$i) {
        echo "This is task 1 iteration {$i}.\n";
        yield;
    }
}
function task2()
{
    for ($i = 1; $i <= 5; ++$i) {
        echo "This is task 2 iteration {$i}.\n";
        yield;
    }
}
$scheduler = new Scheduler();
$scheduler->newTask(task1());
$scheduler->newTask(task2());
$scheduler->run();
}
function task2()
{
    for ($i = 1; $i <= 6; $i++) {
        $data = yield;
        echo '<p>Tâche 2, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
function task3()
{
    for ($i = 1; $i <= 4; $i++) {
        $data = yield;
        echo '<p>Tâche 3, itération ' . $i . ', valeur envoyée : ' . $data . '</p>';
    }
}
$taskRunner->addTask(task1());
$taskRunner->addTask(task2());
$taskRunner->addTask(task3());
$taskRunner->run();
?>
  
                </p>
                
                
                <h2>La méthode throw()</h2>
                <p><strong>Lancer une exception à l'emplacement du <code>yield</code> dans le générateur - accepte un seul argument</strong></p>
                <p class="col-sm-12">
                <?php 
// Génére une fatal error - normal - une exception est lancée par PHP
//                function generator3() {
//                    echo "<p>Début</p>";