PHPDaemon\Core\DeferredEvent::addListener PHP Method

addListener() public method

Add listener
public addListener ( callable $cb ) : void
$cb callable Callback
return void
    public function addListener($cb)
    {
        if ($this->state === self::STATE_DONE) {
            if ($cb !== null) {
                $cb($this);
            }
            return;
        }
        if ($cb !== null) {
            $this->listeners->push($cb);
        }
        if ($this->state === self::STATE_WAITING) {
            $i = 1;
            $n = func_num_args();
            while ($i < $n) {
                $this->args[] = func_get_arg($i);
                ++$i;
            }
            $this->state = self::STATE_RUNNING;
            $func = $this->producer;
            $func($this);
        }
    }