xp_exhaust

xp_exhaust($limit, $process)

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.

Parameters:callable|process – PHP Callable or Process.
Return type:object Process

Example #1 Basic Usage

Defines the given process with an exhaust of 5.

<?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.

foofoofoofoofoo

Example #2 Creating a timeout

<?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.

This will execute only once.