Skip to content

Commit

Permalink
Merge pull request #891 from Cysharp/feature/UpgradeLangVersion
Browse files Browse the repository at this point in the history
Upgrade LangVersion
  • Loading branch information
mayuki authored Jan 7, 2025
2 parents f83077a + 9ca5dc1 commit e497b16
Show file tree
Hide file tree
Showing 80 changed files with 7,264 additions and 7,543 deletions.
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<!-- LangVersion of Client, Abstractions, Shared must match supported Unity version-->
<PropertyGroup>
<LangVersion>latest</LangVersion>
<_LangVersionUnityBaseline>9.0</_LangVersionUnityBaseline>
</PropertyGroup>

<PropertyGroup>
Expand Down
30 changes: 12 additions & 18 deletions src/MagicOnion.Abstractions/Client/IResponseContext.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
using Grpc.Core;
using MessagePack;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Grpc.Core;

namespace MagicOnion.Client
namespace MagicOnion.Client;

public interface IResponseContext : IDisposable
{
public interface IResponseContext : IDisposable
{
Task<Metadata> ResponseHeadersAsync { get; }
Status GetStatus();
Metadata GetTrailers();
Type ResponseType { get; }
}
Task<Metadata> ResponseHeadersAsync { get; }
Status GetStatus();
Metadata GetTrailers();
Type ResponseType { get; }
}

public interface IResponseContext<T> : IResponseContext
{
Task<T> ResponseAsync { get; }
}
public interface IResponseContext<T> : IResponseContext
{
Task<T> ResponseAsync { get; }
}
147 changes: 70 additions & 77 deletions src/MagicOnion.Abstractions/ClientStreamingResult.cs
Original file line number Diff line number Diff line change
@@ -1,93 +1,86 @@
using Grpc.Core;
using MessagePack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using MagicOnion.Internal;

namespace MagicOnion
namespace MagicOnion;

/// <summary>
/// Wrapped AsyncClientStreamingCall.
/// </summary>
public struct ClientStreamingResult<TRequest, TResponse> : IDisposable
{
/// <summary>
/// Wrapped AsyncClientStreamingCall.
/// </summary>
public struct ClientStreamingResult<TRequest, TResponse> : IDisposable
{
internal readonly TResponse? rawValue;
internal readonly bool hasRawValue;
readonly IAsyncClientStreamingCallWrapper<TRequest, TResponse>? inner;
internal readonly TResponse? rawValue;
internal readonly bool hasRawValue;
readonly IAsyncClientStreamingCallWrapper<TRequest, TResponse>? inner;

public ClientStreamingResult(TResponse rawValue)
{
this.hasRawValue = true;
this.rawValue = rawValue;
this.inner = null;
}
public ClientStreamingResult(TResponse rawValue)
{
this.hasRawValue = true;
this.rawValue = rawValue;
this.inner = null;
}

public ClientStreamingResult(IAsyncClientStreamingCallWrapper<TRequest, TResponse> inner)
{
this.hasRawValue = false;
this.rawValue = default(TResponse);
this.inner = inner;
}
public ClientStreamingResult(IAsyncClientStreamingCallWrapper<TRequest, TResponse> inner)
{
this.hasRawValue = false;
this.rawValue = default(TResponse);
this.inner = inner;
}

IAsyncClientStreamingCallWrapper<TRequest, TResponse> GetRequiredInner()
=> inner ?? throw new NotSupportedException("ClientStreamingResult has no inner stream.");
IAsyncClientStreamingCallWrapper<TRequest, TResponse> GetRequiredInner()
=> inner ?? throw new NotSupportedException("ClientStreamingResult has no inner stream.");

/// <summary>
/// Asynchronous call result.
/// </summary>
public Task<TResponse> ResponseAsync
=> hasRawValue ? Task.FromResult(rawValue!) : GetRequiredInner().ResponseAsync;
/// <summary>
/// Asynchronous call result.
/// </summary>
public Task<TResponse> ResponseAsync
=> hasRawValue ? Task.FromResult(rawValue!) : GetRequiredInner().ResponseAsync;

/// <summary>
/// Asynchronous access to response headers.
/// </summary>
public Task<Metadata> ResponseHeadersAsync
=> GetRequiredInner().ResponseHeadersAsync;
/// <summary>
/// Asynchronous access to response headers.
/// </summary>
public Task<Metadata> ResponseHeadersAsync
=> GetRequiredInner().ResponseHeadersAsync;

/// <summary>
/// Async stream to send streaming requests.
/// </summary>
public IClientStreamWriter<TRequest> RequestStream
=> GetRequiredInner().RequestStream;
/// <summary>
/// Async stream to send streaming requests.
/// </summary>
public IClientStreamWriter<TRequest> RequestStream
=> GetRequiredInner().RequestStream;

/// <summary>
/// Allows awaiting this object directly.
/// </summary>
/// <returns></returns>
public TaskAwaiter<TResponse> GetAwaiter()
{
return ResponseAsync.GetAwaiter();
}
/// <summary>
/// Allows awaiting this object directly.
/// </summary>
/// <returns></returns>
public TaskAwaiter<TResponse> GetAwaiter()
{
return ResponseAsync.GetAwaiter();
}

/// <summary>
/// Gets the call status if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Status GetStatus()
=> GetRequiredInner().GetStatus();
/// <summary>
/// Gets the call status if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Status GetStatus()
=> GetRequiredInner().GetStatus();

/// <summary>
/// Gets the call trailing metadata if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Metadata GetTrailers()
=> GetRequiredInner().GetTrailers();
/// <summary>
/// Gets the call trailing metadata if the call has already finished.
/// Throws InvalidOperationException otherwise.
/// </summary>
public Metadata GetTrailers()
=> GetRequiredInner().GetTrailers();

/// <summary>
/// Provides means to cleanup after the call.
/// If the call has already finished normally (request stream has been completed and call result has been received), doesn't do anything.
/// Otherwise, requests cancellation of the call which should terminate all pending async operations associated with the call.
/// As a result, all resources being used by the call should be released eventually.
/// </summary>
/// <remarks>
/// Normally, there is no need for you to dispose the call unless you want to utilize the
/// "Cancel" semantics of invoking <c>Dispose</c>.
/// </remarks>
public void Dispose()
=> inner?.Dispose();
}
/// <summary>
/// Provides means to cleanup after the call.
/// If the call has already finished normally (request stream has been completed and call result has been received), doesn't do anything.
/// Otherwise, requests cancellation of the call which should terminate all pending async operations associated with the call.
/// As a result, all resources being used by the call should be released eventually.
/// </summary>
/// <remarks>
/// Normally, there is no need for you to dispose the call unless you want to utilize the
/// "Cancel" semantics of invoking <c>Dispose</c>.
/// </remarks>
public void Dispose()
=> inner?.Dispose();
}
Loading

0 comments on commit e497b16

Please sign in to comment.