sequenceDiagram

participant ServerBuilder
participant WorkerClient
participant Worker
participant StreamService
participant HttpServiceHandler
participant Tokio

ServerBuilder-->>Tokio: spawn(Worker)

Tokio-->>Worker: poll()
alt WorkerState::Available
	loop
		Worker->>WorkerClient: rx.poll_next()
		WorkerClient->>Worker: WorkerCommand(Conn)
		Worker->>Worker: check_readiness()
		alt check_readiness() -> Ok(true)
			Note over Worker,StreamService: Worker::services[Conn.token]
			Worker-->>StreamService: call(ServerMessage::Connect(stream))
			StreamService->>HttpServiceHandler: call(stream)
			HttpServiceHandler->>StreamService: HttpServiceHandlerResponse as Future
			StreamService->>Tokio: spawn(HttpServiceHandlerResponse)

		else check_readiness() -> Ok(false)
			Worker-->>Worker: WorkerState::Unavailable
		else check_readiness() -> Err(token,idx)
			Worker-->>Worker: WorkerState::Restarting
		end
	end
end


Note over HttpServiceHandler: process connection
