Пример #1
0
/**
 * Nullifies a processes exhaustion rate.
 *
 * .. note::
 *
 *     Once a process is registered with a null exhaust it will **never**
 *     be purged from the processor unless a ``xp_flush`` is called.
 *
 * @param  callable|process  $process  PHP Callable or Process.
 *
 * @return  object  Process
 *
 * @example
 *
 * Example #1 Basic Usage
 *
 * This example installs a null exhaust process which calls an awake signal
 * every 10 seconds creating an interval.
 *
 * .. code-block:: php
 *
 *    <?php
 *    import('time');
 *
 *    time\awake(10, xp_null_exhaust(function(){
 *        echo "10 seconds";
 *    }));
 */
function xp_null_exhaust($process)
{
    if (!$process instanceof \XPSPL\Process) {
        $process = new \XPSPL\Process($process, null);
        return $process;
    }
    $process->set_exhaust(null);
    return $process;
}
Пример #2
0
/**
 * Defines the number of times a process will execute when a signal is emitted.
 *
 * .. note::
 *
 *     By default all processes have an exhaust rate of null.
 *
 * @param  callable|process  $process  PHP Callable or Process.
 *
 * @return  object  Process
 *
 * @example
 *
 * Example #1 Basic Usage
 *
 * Defines the given process with an exhaust of 5.
 *
 * .. code-block:: php
 *
 *    <?php
 *
 * 	  // Install a process for the foo signal that will execute up to 5 times.
 *    xp_signal(XP_SIG('foo'), xp_exhaust(5, function(){
 *        echo 'foo';
 *    });
 *
 *    for($i=0;$i<10;$i++){
 *        xp_emit('foo');
 *    }
 *
 * The above code will output.
 *
 * .. code-block:: php
 *
 *     foofoofoofoofoo
 *
 * @example
 *
 * Example #2 Creating a timeout
 *
 * .. code-block:: php
 *
 *     <?php
 *
 *     // Import the time module
 *     xp_import('time');
 *
 *     time\awake(10, xp_exhaust(1, function(){
 *         echo 'This will execute only once.';
 *     });
 *
 * The above code will output.
 *
 * .. code-block:: php
 *
 *     This will execute only once.
 */
function xp_exhaust($limit, $process)
{
    if (!$process instanceof \XPSPL\Process) {
        $process = new \XPSPL\Process($process, $limit);
        return $process;
    }
    $process->set_exhaust($limit);
    return $process;
}