mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 14:51:41 +01:00
46 lines
1.2 KiB
C#
46 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
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 bool IsTailCall => false;
|
|
|
|
public ConsumedCapability Access(MemberAccessPath access)
|
|
{
|
|
return new LocalAnswerCapability(WhenReturned, access);
|
|
}
|
|
|
|
public ConsumedCapability Access(MemberAccessPath _, Task<IDisposable?> task)
|
|
{
|
|
return new LocalAnswerCapability(task.AsProxyTask());
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
try { _cts.Cancel(); }
|
|
catch (ObjectDisposedException) { }
|
|
}
|
|
}
|
|
} |