src/Messenger.php
function prepareWorker(\CharlotteDunois\Phoebe\Worker $worker) {
        if($this->sockets) {
            $socket = new \CharlotteDunois\Phoebe\Socket($worker->id);
            $worker->setSocket($socket);
            
            $sock = $socket->getPoolSocket();
            
            $stream = new \CharlotteDunois\Phoebe\ResourceSocket($sock, $this->loop);
            $this->streams->set($worker->id, $stream);
            
            $buffer = '';
            $stream->on('data', function ($data) use (&$buffer, &$worker) {
                try {
                    $buffer .= $data;
                    
                    $msgs = \CharlotteDunois\Phoebe\Socket::decodeMessages($buffer);
                    $buffer = \array_shift($msgs);
                    
                    foreach($msgs as $message) {
                        $this->pool->handleMessage($worker, $message);
                    }
                } catch (\Throwable $error) {
                    $this->pool->emit('error', $error);
                }
            });
            
            $stream->on('error', function ($error) {
                $this->pool->emit('error', $error);
            });
            
            $stream->on('close', function () use ($worker) {
                $this->pool->handleStreamClose($worker);
            });
        }
    }
function prepareWorker(\CharlotteDunois\Phoebe\Worker $worker) {
        if($this->sockets) {
            $socket = new \CharlotteDunois\Phoebe\Socket($worker->id);
            $worker->setSocket($socket);
            
            $sock = $socket->getPoolSocket();
            
            $stream = new \CharlotteDunois\Phoebe\ResourceSocket($sock, $this->loop);
            $this->streams->set($worker->id, $stream);
            
            $buffer = '';
            $stream->on('data', function ($data) use (&$buffer, &$worker) {
                try {
                    $buffer .= $data;
                    
                    $msgs = \CharlotteDunois\Phoebe\Socket::decodeMessages($buffer);
                    $buffer = \array_shift($msgs);
                    
                    foreach($msgs as $message) {
                        $this->pool->handleMessage($worker, $message);
                    }
                } catch (\Throwable $error) {
                    $this->pool->emit('error', $error);
                }
            });
            
            $stream->on('error', function ($error) {
                $this->pool->emit('error', $error);
            });
            
            $stream->on('close', function () use ($worker) {
                $this->pool->handleStreamClose($worker);
            });
        }
    }
Prepares the worker if needed.
@param \CharlotteDunois\Phoebe\Worker  $worker
@return void