diff --git a/Capnp.Net.Runtime/Rpc/Impatient.cs b/Capnp.Net.Runtime/Rpc/Impatient.cs index bc497fa..42265dd 100644 --- a/Capnp.Net.Runtime/Rpc/Impatient.cs +++ b/Capnp.Net.Runtime/Rpc/Impatient.cs @@ -45,8 +45,19 @@ namespace Capnp.Rpc if (rtask.IsCompleted) { // Force .NET to create a new Task instance - var stask = rtask; - rtask = new Task(() => stask.Result); + if (rtask.IsCanceled) + { + rtask = Task.FromCanceled(new CancellationToken(true)); + } + else if (rtask.IsFaulted) + { + rtask = Task.FromException(rtask.Exception.InnerException); + } + else + { + rtask = Task.FromResult(rtask.Result); + } + _taskTable.Add(rtask, promise); } else