Skip to content

Commit 95e6a82

Browse files
schwmiglbrntt
andauthored
Allow to finish() GRPCAsyncRequestStreamWriter sync, non-throwing (#1504)
* Add sync method variant for finishing RequestStreamWriter * Adjust call sites to use sync RequestStreamWriter finish * Remove async variant of GRPCAsyncRequestStreamWriter's .finish() Co-authored-by: George Barnett <[email protected]>
1 parent 930667f commit 95e6a82

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

Sources/Examples/RouteGuide/Client/RouteGuideClient.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ extension RouteGuideExample {
143143
}
144144
}
145145

146-
try await recordRoute.requestStream.finish()
146+
recordRoute.requestStream.finish()
147147
let summary = try await recordRoute.response
148148

149149
print(
@@ -188,7 +188,7 @@ extension RouteGuideExample {
188188
try await Task.sleep(nanoseconds: UInt64.random(in: UInt64(2e8) ... UInt64(1e9)))
189189
}
190190

191-
try await routeChat.requestStream.finish()
191+
routeChat.requestStream.finish()
192192
}
193193

194194
// Add a task to print each message received on the response stream.

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncRequestStreamWriter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public struct GRPCAsyncRequestStreamWriter<Request: Sendable>: Sendable {
8686
}
8787

8888
/// Finish the request stream for the RPC. This must be called when there are no more requests to be sent.
89-
public func finish() async throws {
89+
public func finish() {
9090
self.asyncWriter.finish()
9191
}
9292

Sources/GRPC/AsyncAwaitSupport/GRPCClient+AsyncAwaitSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ extension GRPCClient {
421421
for try await request in requests {
422422
try await call.requestStream.send(request)
423423
}
424-
try await call.requestStream.finish()
424+
call.requestStream.finish()
425425
} catch {
426426
// If we throw then cancel the call. We will rely on the response throwing an appropriate
427427
// error below.
@@ -452,7 +452,7 @@ extension GRPCClient {
452452
for try await request in requests {
453453
try await call.requestStream.send(request)
454454
}
455-
try await call.requestStream.finish()
455+
call.requestStream.finish()
456456
} onCancel: {
457457
call.cancel()
458458
}

Tests/GRPCTests/AsyncAwaitSupport/AsyncClientTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ final class AsyncClientCancellationTests: GRPCTestCase {
222222
let collect = echo.makeCollectCall()
223223
// Send and close.
224224
try await collect.requestStream.send(.with { $0.text = "foo" })
225-
try await collect.requestStream.finish()
225+
collect.requestStream.finish()
226226

227227
// Await the response and status.
228228
_ = try await collect.response
@@ -294,7 +294,7 @@ final class AsyncClientCancellationTests: GRPCTestCase {
294294
let update = echo.makeUpdateCall()
295295
// Send and close.
296296
try await update.requestStream.send(.with { $0.text = "foo" })
297-
try await update.requestStream.finish()
297+
update.requestStream.finish()
298298

299299
// Await the response and status.
300300
let responseCount = try await update.responseStream.count()

Tests/GRPCTests/AsyncAwaitSupport/AsyncIntegrationTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ final class AsyncIntegrationTests: GRPCTestCase {
8282
try await collect.requestStream.send(.with { $0.text = "boyle" })
8383
try await collect.requestStream.send(.with { $0.text = "jeffers" })
8484
try await collect.requestStream.send(.with { $0.text = "holt" })
85-
try await collect.requestStream.finish()
85+
collect.requestStream.finish()
8686

8787
let initialMetadata = try await collect.initialMetadata
8888
initialMetadata.assertFirst("200", forName: ":status")
@@ -149,7 +149,7 @@ final class AsyncIntegrationTests: GRPCTestCase {
149149
XCTAssertEqual(response, "Swift echo update (\(i)): \(name)")
150150
}
151151

152-
try await update.requestStream.finish()
152+
update.requestStream.finish()
153153

154154
// This isn't right after we make the call as servers are not guaranteed to send metadata back
155155
// immediately. Concretely, we don't send initial metadata back until the first response
@@ -186,7 +186,7 @@ final class AsyncIntegrationTests: GRPCTestCase {
186186
_ = try await update.responseStream.first(where: { _ in true })
187187
XCTAssertNoThrow(try self.server.close().wait())
188188
self.server = nil // So that tearDown() does not call close() again.
189-
try await update.requestStream.finish()
189+
update.requestStream.finish()
190190
}
191191
}
192192

Tests/GRPCTests/AsyncAwaitSupport/InterceptorsAsyncTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class InterceptorsAsyncTests: GRPCTestCase {
105105
let call = self.echo.makeCollectCall(callOptions: .init())
106106
try await call.requestStream.send(.with { $0.text = "1 2" })
107107
try await call.requestStream.send(.with { $0.text = "3 4" })
108-
try await call.requestStream.finish()
108+
call.requestStream.finish()
109109

110110
await assertThat(
111111
try await call.response,
@@ -153,7 +153,7 @@ class InterceptorsAsyncTests: GRPCTestCase {
153153
let call = self.echo.makeUpdateCall(callOptions: .init())
154154
try await call.requestStream.send(.with { $0.text = "1 2" })
155155
try await call.requestStream.send(.with { $0.text = "3 4" })
156-
try await call.requestStream.finish()
156+
call.requestStream.finish()
157157

158158
var count = 0
159159
for try await response in call.responseStream {

Tests/GRPCTests/GRPCAsyncClientCallTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
9898
for word in ["boyle", "jeffers", "holt"] {
9999
try await collect.requestStream.send(.with { $0.text = word })
100100
}
101-
try await collect.requestStream.finish()
101+
collect.requestStream.finish()
102102

103103
await assertThat(try await collect.initialMetadata, .is(.equalTo(Self.OKInitialMetadata)))
104104
await assertThat(try await collect.response, .doesNotThrow())
@@ -138,7 +138,7 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
138138
try await update.requestStream.send(request)
139139
}
140140
try await update.requestStream.send(requests)
141-
try await update.requestStream.finish()
141+
update.requestStream.finish()
142142

143143
let numResponses = try await update.responseStream.map { _ in 1 }.reduce(0, +)
144144

@@ -163,7 +163,7 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
163163
await assertThat(try await responseStreamIterator.next(), .is(.notNil()))
164164
}
165165

166-
try await update.requestStream.finish()
166+
update.requestStream.finish()
167167

168168
await assertThat(try await responseStreamIterator.next(), .is(.nil()))
169169

@@ -191,7 +191,7 @@ class GRPCAsyncClientCallTests: GRPCTestCase {
191191
try await update.requestStream.send(.with { $0.text = word })
192192
await counter.incrementRequests()
193193
}
194-
try await update.requestStream.finish()
194+
update.requestStream.finish()
195195
}
196196
// Get responses in a separate task.
197197
taskGroup.addTask {

0 commit comments

Comments
 (0)