src/Worker.php
protected function addTimer() {
        if(!(static::$loop instanceof \React\EventLoop\LoopInterface)) {
            throw new \LogicException('No event loop was created');
        }
        
        if(!(static::$me instanceof \CharlotteDunois\Phoebe\Worker)) {
            throw new \LogicException('Contract Worker::$me being the Worker is not met');
        }
        
        if($this->bag->socket !== null) {
            static::$socket = new \CharlotteDunois\Phoebe\ResourceSocket($this->bag->socket->getWorkerSocket(), static::$loop);
            self::$socket = static::$socket;
            
            $buffer = '';
            static::$socket->on('data', function ($data) use (&$buffer) {
                try {
                    $buffer .= $data;
                    
                    $msgs = \CharlotteDunois\Phoebe\Socket::decodeMessages($buffer);
                    $buffer = \array_shift($msgs);
                    
                    foreach($msgs as $message) {
                        if($this->handleMessage($message)) {
                            return;
                        }
                    }
                } catch (\Throwable $e) {
                    $stack = \CharlotteDunois\Phoebe\Message::exportException($e);
                    $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                    $this->sendMessageToPool($message);
                }
            });
            
            static::$socket->on('error', function ($error) {
                static::$socket = null;
                
                $stack = \CharlotteDunois\Phoebe\Message::exportException($error);
                $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                $this->sendMessageToPool($message);
            });
            
            static::$socket->on('close', function () {
                static::$socket = null;
                
                $message = new \CharlotteDunois\Phoebe\Message('internal-worker-exit', null);
                $this->handleMessage($message);
            });
            
            return;
        }
        
        $timer = static::$loop->addPeriodicTimer($this->timerInterval, function () use (&$timer) {
            try {
                while($message = $this->messagesIn->shift()) {
                    if($this->handleMessage($message)) {
                        static::$loop->cancelTimer($timer);
                        return;
                    }
                }
                
                $this->handleStack();
            } catch (\Throwable $e) {
                $stack = \CharlotteDunois\Phoebe\Message::exportException($e);
                $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                $this->sendMessageToPool($message);
            }
        });
        
        if($this->bag->callableOnStart) {
            $callable = $this->bag->callableOnStart;
            $callable();
        }
    }
protected function addTimer() {
        if(!(static::$loop instanceof \React\EventLoop\LoopInterface)) {
            throw new \LogicException('No event loop was created');
        }
        
        if(!(static::$me instanceof \CharlotteDunois\Phoebe\Worker)) {
            throw new \LogicException('Contract Worker::$me being the Worker is not met');
        }
        
        if($this->bag->socket !== null) {
            static::$socket = new \CharlotteDunois\Phoebe\ResourceSocket($this->bag->socket->getWorkerSocket(), static::$loop);
            self::$socket = static::$socket;
            
            $buffer = '';
            static::$socket->on('data', function ($data) use (&$buffer) {
                try {
                    $buffer .= $data;
                    
                    $msgs = \CharlotteDunois\Phoebe\Socket::decodeMessages($buffer);
                    $buffer = \array_shift($msgs);
                    
                    foreach($msgs as $message) {
                        if($this->handleMessage($message)) {
                            return;
                        }
                    }
                } catch (\Throwable $e) {
                    $stack = \CharlotteDunois\Phoebe\Message::exportException($e);
                    $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                    $this->sendMessageToPool($message);
                }
            });
            
            static::$socket->on('error', function ($error) {
                static::$socket = null;
                
                $stack = \CharlotteDunois\Phoebe\Message::exportException($error);
                $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                $this->sendMessageToPool($message);
            });
            
            static::$socket->on('close', function () {
                static::$socket = null;
                
                $message = new \CharlotteDunois\Phoebe\Message('internal-worker-exit', null);
                $this->handleMessage($message);
            });
            
            return;
        }
        
        $timer = static::$loop->addPeriodicTimer($this->timerInterval, function () use (&$timer) {
            try {
                while($message = $this->messagesIn->shift()) {
                    if($this->handleMessage($message)) {
                        static::$loop->cancelTimer($timer);
                        return;
                    }
                }
                
                $this->handleStack();
            } catch (\Throwable $e) {
                $stack = \CharlotteDunois\Phoebe\Message::exportException($e);
                $message = new \CharlotteDunois\Phoebe\Message('internal-error-handling', $stack);
                $this->sendMessageToPool($message);
            }
        });
        
        if($this->bag->callableOnStart) {
            $callable = $this->bag->callableOnStart;
            $callable();
        }
    }
Adds the timer or creates the socket. Also invokes the callable, if there is one.
@return void
@internal
@codeCoverageIgnore