Skip to content

gowork/throttler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Throttler

Build Status

Use the throttle to control the speed.

use GW\Throttler\Throttler;

$throttler = new Throttler(1.0);

foreach ($heavyTasks->all() as $task) {
    $throttler->throttle(); // wait a second... before next task
    $task->run();
}

Alternative usage for wrapping iterables:

use GW\Throttler\Throttler;

$throttledTask = Throttler::iterable($heavyTasks->all(), 1.0);

foreach ($throttledTask as $task) {
    $task->run(); // for each iteration it will sleep one second
}