Skip to content

Commit da20f7d

Browse files
fixup: Add section on desire for opaque return types
Signed-off-by: Si Beaumont <[email protected]>
1 parent 8e9b6e0 commit da20f7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

docs/async-await-proposal.md

+20
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,27 @@ async/await language constructs), they provide throwing APIs to access the final
436436
metadata for the RPC. We could consider doing the same and have not ruled it
437437
out.
438438

439+
### Opaque return type for response streams
440+
441+
It would be nice if we didn't have to return the `GRPCAsyncStream` wrapper type
442+
for server-streaming RPCs. Ideally we would be able to declare an opaque return
443+
type with a constraint on its associated type. This would make the return type of
444+
server-streaming calls more symmetric with the inputs to client-streaming calls.
445+
For example, the bidirectional API could be defined as follows:
446+
447+
```swift
448+
func update<RequestStream>(
449+
requests: RequestStream,
450+
callOptions: CallOptions? = nil
451+
) -> some AsyncSequence where Element == Echo_EchoResponse
452+
where RequestStream: AsyncSequence, RequestStream.Element == Echo_EchoRequest
453+
```
454+
455+
Unfortunately this isn't currently supported by `AsyncSequence`, but it _has_
456+
been called out as a [possible future enhancement][opaque-asyncsequence].
457+
439458
[SE-0296]: https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md
440459
[SE-0298]: https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md
441460
[SE-0310]: https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md
442461
[SE-0314]: https://github.com/apple/swift-evolution/blob/main/proposals/0314-async-stream.md
462+
[opaque-asyncsequence]: https://github.com/apple/swift-evolution/blob/0c2f85b3/proposals/0298-asyncsequence.md#opaque-types

0 commit comments

Comments
 (0)