Skip to content

Commit 4c49678

Browse files
committed
prefer ValueTask<T> for ResponseHeadersAsync()
1 parent 0e04570 commit 4c49678

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/protobuf-net.Grpc/CallContext.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ public CallContext(in CallOptions callOptions = default, CallContextFlags flags
166166
/// Get the response-headers from a client operation when they are available
167167
/// </summary>
168168
[MethodImpl(MethodImplOptions.AggressiveInlining)]
169-
public Task<Metadata> ResponseHeadersAsync() => MetadataContext?.GetHeadersTask(true)
170-
?? Task.FromResult(ThrowNoContext<Metadata>()); // note this actually throws immediately; this is intentional
169+
public ValueTask<Metadata> ResponseHeadersAsync()
170+
{ // exposing as ValueTask<T> to retain ability to change API internals later, but currently just wraps Task<T>
171+
var task = MetadataContext?.GetHeadersTask(true);
172+
return task is object
173+
? new ValueTask<Metadata>(task)
174+
: new ValueTask<Metadata>(ThrowNoContext<Metadata>());// note this actually throws immediately; this is intentional
175+
}
171176

172177
/// <summary>
173178
/// Get the response-trailers from a client operation

0 commit comments

Comments
 (0)