Skip to content

Commit

Permalink
Even simpler!
Browse files Browse the repository at this point in the history
  • Loading branch information
twogood committed Nov 26, 2024
1 parent d8803cb commit 4538025
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions Activout.RestClient/Helpers/Implementation/TaskConverter3.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;

namespace Activout.RestClient.Helpers.Implementation;

/*
* Convert from Task<object> to Task<T> where T is the Type
*
* Implemented by creating a TaskCompletionSource<T> and setting the result or exception
*/
public class TaskConverter3<T> : ITaskConverter
{
Expand All @@ -20,16 +17,6 @@ public object ConvertReturnType(Task<object> task)
[StackTraceHidden]
private static async Task<T> ConvertReturnTypeImpl(Task<object> task)
{
var taskCompletionSource = new TaskCompletionSource<T>();
try
{
taskCompletionSource.SetResult((T)await task);
}
catch (Exception e)
{
taskCompletionSource.SetException(e);
}

return await taskCompletionSource.Task;
return (T)await task;
}
}

0 comments on commit 4538025

Please sign in to comment.