function handleMessage(\CharlotteDunois\Phoebe\Worker $worker, \CharlotteDunois\Phoebe\Message $message) {
        $type = $message->getType();
        
        switch($type) {
            case 'internal-error-handling':
                $error = \CharlotteDunois\Phoebe\Message::importException($message->getPayload());
                $this->emit('error', $error);
            break;
            case 'internal-thread-done':
                $this->handleThreadDone($message);
            break;
            case 'internal-worker-stack-free':
                if($this->workQueue->count() > 0) {
                    /** @var \CharlotteDunois\Phoebe\InternalWork  $work */
                    $work = $this->workQueue->dequeue();
                    
                    $worker->stack($work->getWork());
                    
                    if($this->messenger->usesSockets()) {
                        $msg = new \CharlotteDunois\Phoebe\Message('internal-worker-stack-increased', null);
                        $this->sendMessageToWorker($worker, $msg);
                    }
                    
                    $work->getDeferred()->resolve($worker);
                    return;
                }
                
                $this->busyWorkers->delete($worker);
                $this->freeWorkers->enqueue($worker);
            break;
            default:
                $this->emit('message', $worker, $message);
            break;
        }
    }