Repository: vapor/vapor
File: Sources/Vapor/Server/NIOServer.swift (Swift)

Code before:
/// Vapor's default `Server` implementation. Built on SwiftNIO-based `HTTPServer`.
public final class NIOServer: Server, ServiceType {
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Server.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> NIOServer {
        return try NIOServer(config: container.make(), container: container)
    }

    /// Chosen configuration for this server.
    public let config: NIOServerConfig

    /// Container for setting on event loops.
    public fileprivate(set) weak var container: Container!

    /// Create a new `NIOServer`.
    ///
    /// - parameters:
    ///     - config: Server preferences such as hostname, port, max body size, etc.
    ///     - container: Root service-container to use for all event loops the server will create.
    public init(config: NIOServerConfig, container: Container) {
        self.config = config
        self.container = container
    }

    /// See `Server`.
    public func start(hostname: String?, port: Int?) -> Future<Void> {
        do {
            // console + logger required for outputting messages and error info
            let console = try container.make(Console.self)
            let logger = try container.make(Logger.self)

            // determine which hostname / port to bind to
            let hostname = hostname ?? config.hostname
            let port = port ?? config.port

            // print starting message
            console.print("Server starting on ", newLine: false)
            console.output("http://" + hostname, style: .init(color: .cyan), newLine: false)
            console.output(":" + port.description, style: .init(color: .cyan))

            // create caches

Review comment (suggestion):
I removed `currentWorker` since:

1. It was not implemented
2. If it were implemented, it'd always point to `container` anyways (unless I missed something)

Code after:
/// Vapor's default `Server` implementation. Built on SwiftNIO-based `HTTPServer`.
public final class NIOServer: Server, ServiceType {
    /// See `ServiceType`.
    public static var serviceSupports: [Any.Type] { return [Server.self] }

    /// See `ServiceType`.
    public static func makeService(for container: Container) throws -> NIOServer {
        return try NIOServer(config: container.make(), container: container)
    }

    /// Chosen configuration for this server.
    public let config: NIOServerConfig

    /// Container for setting on event loops.
    public fileprivate(set) weak var container: Container!

    /// Hold the current worker. Used for deinit.
    private var currentWorker: Worker?

    /// Create a new `NIOServer`.
    ///
    /// - parameters:
    ///     - config: Server preferences such as hostname, port, max body size, etc.
    ///     - container: Root service-container to use for all event loops the server will create.
    public init(config: NIOServerConfig, container: Container) {
        self.config = config
        self.container = container
    }

    /// See `Server`.
    public func start(hostname: String?, port: Int?) -> Future<Void> {
        do {
            // console + logger required for outputting messages and error info
            let console = try container.make(Console.self)
            let logger = try container.make(Logger.self)

            // determine which hostname / port to bind to
            let hostname = hostname ?? config.hostname
            let port = port ?? config.port

            // print starting message
            console.print("Server starting on ", newLine: false)
            console.output("http://" + hostname, style: .init(color: .cyan), newLine: false)