public function addJob($name, $cb)
{
if (isset($this->jobs[$name])) {
return false;
}
$cb = CallbackWrapper::wrap($cb);
if ($this->maxConcurrency !== -1 && $this->jobsNum - $this->resultsNum > $this->maxConcurrency) {
if ($this->backlog === null) {
$this->backlog = new \SplStack();
}
$this->backlog->push([$name, $cb]);
return true;
}
$this->jobs[$name] = $cb;
++$this->jobsNum;
if ($this->state === self::STATE_RUNNING || $this->state === self::STATE_DONE) {
$this->state = self::STATE_RUNNING;
$cb($name, $this);
}
return true;
}