mpyw\Co\Internal\Delayer::consume PHP Method

consume() public method

Consume delay queue.
public consume ( )
    public function consume()
    {
        foreach ($this->untils as $id => $until) {
            $diff = $until - microtime(true);
            if ($diff > 0.0 || !isset($this->deferreds[$id])) {
                continue;
            }
            $deferred = $this->deferreds[$id];
            unset($this->deferreds[$id], $this->untils[$id]);
            $deferred->resolve(null);
        }
    }

Usage Example

Example #1
0
File: Pool.php Project: mpyw/co
 /**
  * Run curl_multi_exec() loop.
  */
 public function wait()
 {
     curl_multi_exec($this->mh, $active);
     // Start requests.
     do {
         // if cURL handle is running, use curl_multi_select()
         // otherwise, just sleep until nearest time
         $this->scheduler->isEmpty() ? $this->delayer->sleep() : curl_multi_select($this->mh, $this->options['interval']) < 0 && usleep($this->options['interval'] * 1000000);
         curl_multi_exec($this->mh, $active);
         $this->scheduler->consume();
         $this->delayer->consume();
     } while (!$this->haltException && (!$this->scheduler->isEmpty() || !$this->delayer->isEmpty()));
     if ($this->haltException) {
         throw $this->haltException;
     }
 }