. ,
, ,
. myloop() ,
, .
4 ( ).
, , ,
, .
:
myloop() ---> queue
^ v
| |
'<-processor <-'
<?php
<?php
function send_item_to_processor($item, $data, $index, $counter) {
}
function myloop($data, $index = 0, $counter = 0) {
if (!isset($data[$index])) {
return;
}
$currentItem = $data[$index];
$currentItem()->then(function() use ($data, $index) {
send_item_to_processor($currentItem, $data, $index + 1, $counter + 1);
});
}
function process_new_items() {
if (ITEM_COUNT == 0 || $ACTIVE_COUNT >= $ITEM_CONCURRENT_MAX)
return FALSE;
return TRUE;
}
function process_queue() {
if (!process_new_items())
return FALSE;
$numComplete = count($rows);
foreach($rows as $item) {
if (is_invalid(pid) || $status == finished) {
myloop(data, index, counter - 1);
}
}
}