mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 23:01:44 +01:00
54 lines
1.2 KiB
C#
54 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
#nullable enable
|
|
namespace Capnp.Rpc
|
|
{
|
|
class LocalAnswer : IPromisedAnswer
|
|
{
|
|
readonly CancellationTokenSource _cts;
|
|
|
|
public LocalAnswer(CancellationTokenSource cts, Task<DeserializerState> call)
|
|
{
|
|
_cts = cts ?? throw new ArgumentNullException(nameof(cts));
|
|
WhenReturned = call ?? throw new ArgumentNullException(nameof(call));
|
|
|
|
CleanupAfterReturn();
|
|
}
|
|
|
|
async void CleanupAfterReturn()
|
|
{
|
|
try
|
|
{
|
|
await WhenReturned;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
finally
|
|
{
|
|
_cts.Dispose();
|
|
}
|
|
}
|
|
|
|
public Task<DeserializerState> WhenReturned { get; }
|
|
|
|
public ConsumedCapability Access(MemberAccessPath access)
|
|
{
|
|
return new LocalAnswerCapability(WhenReturned, access);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try
|
|
{
|
|
_cts.Cancel();
|
|
}
|
|
catch (ObjectDisposedException)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#nullable restore |