Skip to content

Remove unnecessary self keyword #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {

deinit {
debug("Output stream delegate deinit")
self.outputStream.delegate = nil
outputStream.delegate = nil
}

func performAction(_ action: State.Action) {
Expand All @@ -48,7 +48,7 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
case .none: return
case .resumeProducer(let producerContinuation):
producerContinuation.resume()
performAction(self.state.resumedProducer())
performAction(state.resumedProducer())
case .writeBytes(let chunk): writePendingBytes(chunk)
case .cancelProducerAndCloseStream(let producerContinuation):
producerContinuation.resume(throwing: CancellationError())
Expand All @@ -75,31 +75,28 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
self.performAction(self.state.wroteFinalChunk())
}
}
self.performAction(self.state.startedProducerTask(task))
performAction(state.startedProducerTask(task))
}

private func writePendingBytes(_ bytesToWrite: Chunk) {
dispatchPrecondition(condition: .onQueue(Self.streamQueue))
precondition(!bytesToWrite.isEmpty, "\(#function) must be called with non-empty bytes")
guard outputStream.streamStatus == .open else {
debug("Output stream closed unexpectedly.")
performAction(self.state.wroteBytes(numBytesWritten: 0, streamStillHasSpaceAvailable: false))
performAction(state.wroteBytes(numBytesWritten: 0, streamStillHasSpaceAvailable: false))
return
}
switch bytesToWrite.withUnsafeBytes({ outputStream.write($0.baseAddress!, maxLength: bytesToWrite.count) }) {
case 0:
debug("Output stream delegate reached end of stream when writing.")
performAction(self.state.endEncountered())
performAction(state.endEncountered())
case -1:
debug("Output stream delegate encountered error writing to stream: \(outputStream.streamError!).")
performAction(self.state.errorOccurred(outputStream.streamError!))
performAction(state.errorOccurred(outputStream.streamError!))
case let written where written > 0:
debug("Output stream delegate wrote \(written) bytes to stream.")
performAction(
self.state.wroteBytes(
numBytesWritten: written,
streamStillHasSpaceAvailable: outputStream.hasSpaceAvailable
)
state.wroteBytes(numBytesWritten: written, streamStillHasSpaceAvailable: outputStream.hasSpaceAvailable)
)
default: preconditionFailure("OutputStream.write(_:maxLength:) returned undocumented value")
}
Expand All @@ -115,9 +112,9 @@ final class HTTPBodyOutputStreamBridge: NSObject, StreamDelegate {
return
}
startWriterTask()
case .hasSpaceAvailable: performAction(self.state.spaceBecameAvailable())
case .errorOccurred: performAction(self.state.errorOccurred(stream.streamError!))
case .endEncountered: performAction(self.state.endEncountered())
case .hasSpaceAvailable: performAction(state.spaceBecameAvailable())
case .errorOccurred: performAction(state.errorOccurred(stream.streamError!))
case .endEncountered: performAction(state.endEncountered())
default:
debug("Output stream ignoring event: \(event).")
break
Expand Down
6 changes: 2 additions & 4 deletions Sources/OpenAPIURLSession/URLSessionTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public struct URLSessionTransport: ClientTransport {
public func send(_ request: HTTPRequest, body requestBody: HTTPBody?, baseURL: URL, operationID: String)
async throws -> (HTTPResponse, HTTPBody?)
{
switch self.configuration.implementation {
switch configuration.implementation {
case .streaming(let requestBodyStreamBufferSize, let responseBodyStreamWatermarks):
#if canImport(Darwin)
guard #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) else {
Expand Down Expand Up @@ -193,9 +193,7 @@ extension URLRequest {
}
self.init(url: url)
self.httpMethod = request.method.rawValue
for header in request.headerFields {
self.setValue(header.value, forHTTPHeaderField: header.name.canonicalName)
}
for header in request.headerFields { setValue(header.value, forHTTPHeaderField: header.name.canonicalName) }
}
}

Expand Down