Repository: vapor/vapor
File: Sources/Vapor/HTTP/EndpointCache.swift (Swift)

Code before:

    private let sync: Lock
    private let uri: URI

    /// The designated initializer.
    /// - Parameters:
    ///   - uri: The `URI` of the resource to be downloaded.
    public init(uri: URI) {
        self.uri = uri
        self.sync = .init()
    }

    /// Downloads the resource.
    /// - Parameters:
    ///   - request: The `Request` which is initiating the download.
    ///   - logger: An optional logger
    public func get(on request: Request, logger: Logger? = nil) -> EventLoopFuture<T> {
        return self.download(on: request.eventLoop, using: request.client, logger: logger)
    }

    /// Downloads the resource.
    /// - Parameters:
    ///   - eventLoop: The `EventLoop` to use for the download.
    ///   - client: The `Client` which will perform the download.
    ///   - logger: An optional logger
    public func get(on eventLoop: EventLoop, using client: Client, logger: Logger?) -> EventLoopFuture<T> {
        self.sync.lock()
        defer { self.sync.unlock() }

        if let cached = self.cached, let cacheUntil = self.cacheUntil, Date() < cacheUntil {
            // If no-cache was set on the header, you *always* have to validate with the server.
            // must-revalidate does not require checking with the server until after it expires.
            if self.headers == nil || self.headers?.cacheControl == nil || self.headers?.cacheControl?.noCache == false {
                return eventLoop.makeSucceededFuture(cached)
            }
        }

        // Don't make a new request if one is already running.
        if let request = self.request {
            // The current request may be happening on a different event loop.
            return request.hop(to: eventLoop)
        }

        logger?.debug("Requesting data from \(self.uri)")

        self.request = self.download(on: eventLoop, using: client, logger: logger)

        // Once the request finishes, clear the current request and return the data.
        return self.request!.map { data in
            // Synchronize access to shared state
            self.sync.lock()

Review comment (suggestion):
`on` parameters are typically the last argument to methods (this includes the previous method, too). We should also have `logger: Logger? = nil` as a default parameter here. 

Code after:
    private let sync: Lock
    private let uri: URI

    /// The designated initializer.
    /// - Parameters:
    ///   - uri: The `URI` of the resource to be downloaded.
    public init(uri: URI) {
        self.uri = uri
        self.sync = .init()
    }

    /// Downloads the resource.
    /// - Parameters:
    ///   - request: The `Request` which is initiating the download.
    ///   - logger: An optional logger
    public func get(on request: Request, logger: Logger? = nil) -> EventLoopFuture<T> {
        return self.download(on: request.eventLoop, using: request.client, logger: logger ?? request.logger)
    }

    /// Downloads the resource.
    /// - Parameters:
    ///   - eventLoop: The `EventLoop` to use for the download.
    ///   - client: The `Client` which will perform the download.
    ///   - logger: An optional logger
    public func get(using client: Client, logger: Logger? = nil, on eventLoop: EventLoop) -> EventLoopFuture<T> {
        self.sync.lock()
        defer { self.sync.unlock() }

        if let cached = self.cached, let cacheUntil = self.cacheUntil, Date() < cacheUntil {
            // If no-cache was set on the header, you *always* have to validate with the server.
            // must-revalidate does not require checking with the server until after it expires.
            if self.headers == nil || self.headers?.cacheControl == nil || self.headers?.cacheControl?.noCache == false {
                return eventLoop.makeSucceededFuture(cached)
            }
        }

        // Don't make a new request if one is already running.
        if let request = self.request {
            // The current request may be happening on a different event loop.
            return request.hop(to: eventLoop)
        }

        logger?.debug("Requesting data from \(self.uri)")

        let request = self.download(on: eventLoop, using: client, logger: logger)
        self.request = request

        // Once the request finishes, clear the current request and return the data.
        return request.map { data in
            // Synchronize access to shared state
            self.sync.lock()