-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Creating async local controlled Channel
- Loading branch information
1 parent
56c1f3d
commit f19cdcb
Showing
8 changed files
with
385 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Codibre.GrpcSqlProxy.Client/Impl/SqlProxyClientTunnel.ContextInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Codibre.GrpcSqlProxy.Api; | ||
using Grpc.Core; | ||
|
||
namespace Codibre.GrpcSqlProxy.Client.Impl; | ||
|
||
public sealed partial class SqlProxyClientTunnel | ||
{ | ||
internal class ContextInfo : IDisposable | ||
{ | ||
private readonly Action _clear; | ||
private readonly ExecutionContext? _executionContext; | ||
public bool Disposed { get; private set; } = false; | ||
public bool Transaction { get; set; } = false; | ||
public AsyncDuplexStreamingCall<SqlRequest, SqlResponse> Stream { get; } | ||
public SqlProxyClientResponseMonitor Monitor { get; } | ||
public ContextInfo( | ||
Func<AsyncDuplexStreamingCall<SqlRequest, SqlResponse>> getStream, | ||
Action clear | ||
) | ||
{ | ||
Stream = getStream(); | ||
Monitor = new(Stream); | ||
_clear = clear; | ||
_executionContext = ExecutionContext.Capture(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Monitor.Dispose(); | ||
Stream.Dispose(); | ||
Disposed = true; | ||
if (_executionContext is not null) ExecutionContext.Run(_executionContext, (_) => _clear(), null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Codibre.GrpcSqlProxy.Client/Impl/SqlProxyClientTunnelExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Concurrent; | ||
using System.Text.Json; | ||
using System.Threading.Channels; | ||
using System.Transactions; | ||
using Avro; | ||
using Avro.Generic; | ||
using Avro.IO; | ||
using Codibre.GrpcSqlProxy.Api; | ||
using Codibre.GrpcSqlProxy.Client.Impl.Utils; | ||
using Codibre.GrpcSqlProxy.Common; | ||
using Google.Protobuf.Collections; | ||
using Grpc.Core; | ||
|
||
namespace Codibre.GrpcSqlProxy.Client.Impl; | ||
|
||
public static class SqlProxyClientTunnelExtension | ||
{ | ||
public static ValueTask<T?> QueryFirstOrDefault<T>( | ||
this ISqlProxyClientTunnel tunnel, | ||
string sql, | ||
SqlProxyQueryOptions? options = null | ||
) where T : class, new() | ||
=> tunnel.Query<T>(sql, options).FirstOrDefaultAsync(); | ||
|
||
public static ValueTask<T> QueryFirst<T>( | ||
this ISqlProxyClientTunnel tunnel, | ||
string sql, | ||
SqlProxyQueryOptions? options = null | ||
) where T : class, new() | ||
=> tunnel.Query<T>(sql, options).FirstAsync(); | ||
|
||
|
||
internal static async ValueTask Complete<T>(this IAsyncEnumerable<T> stream) | ||
{ | ||
await foreach (var _ in stream) | ||
{ | ||
// Dummy | ||
} | ||
} | ||
} |
Oops, something went wrong.