Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CodeJam.Main.Tests/TestTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

using CodeJam.Strings;
using CodeJam.Targeting;
Expand Down Expand Up @@ -69,6 +70,40 @@ private static void PrintProps([NotNull] string typeName)
Console.WriteLine($"\t * {prop.Name}: {prop.GetValue(null, null)}");
}
}

public static void WaitForResult([NotNull] this Task source)
{
#if NET45_OR_GREATER || TARGETS_NETCOREAPP
source.GetAwaiter().GetResult();
#else
// Workaround for Theraot cancellation logic
try
{
source.GetAwaiter().GetResult();
}
catch (TaskCanceledException ex)
{
throw new OperationCanceledException(ex.Message, ex);
}
#endif
}

public static T WaitForResult<T>([NotNull] this Task<T> source)
{
#if NET45_OR_GREATER || TARGETS_NETCOREAPP
return source.GetAwaiter().GetResult();
#else
// Workaround for Theraot cancellation logic
try
{
return source.GetAwaiter().GetResult();
}
catch (TaskCanceledException ex)
{
throw new OperationCanceledException(ex.Message, ex);
}
#endif
}
}

public class Holder<T>
Expand Down
Loading