コード例 #1
0
 /**
  * @inheritDoc
  */
 public function peek($index = 0, $limit = 20)
 {
     $it = new \InfiniteIterator(new \ArrayIterator($this->queues));
     $envelopes = $drained = $indexes = [];
     foreach (array_keys($this->queues) as $name) {
         $indexes[$name] = 0;
     }
     $shift = 0;
     $key = key($this->queues);
     for ($it->rewind(); $it->key() != $key; $it->next()) {
         // noop
     }
     while (count($envelopes) < $limit && count($drained) < $it->count()) {
         $queue = $it->current();
         $name = $it->key();
         if ($peeked = $queue->peek($indexes[$name], 1)) {
             if ($shift < $index) {
                 $shift++;
                 $indexes[$name]++;
             } else {
                 $envelopes[] = array_shift($peeked);
             }
         } else {
             $drained[$name] = true;
         }
         $it->next();
     }
     return $envelopes;
 }