diff --git a/src/ReC.Client/TaskSyncExtensions.cs b/src/ReC.Client/TaskSyncExtensions.cs new file mode 100644 index 0000000..2effd36 --- /dev/null +++ b/src/ReC.Client/TaskSyncExtensions.cs @@ -0,0 +1,26 @@ +#if NETFRAMEWORK +using System.Threading.Tasks; +#endif + +namespace ReC.Client +{ + /// + /// Provides synchronous wrappers for Task-based operations. + /// + public static class TaskSyncExtensions + { + /// + /// Blocks until the task completes and propagates any exception. + /// + /// The task to wait for. + public static void Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult(); + + /// + /// Blocks until the task completes and returns its result, propagating any exception. + /// + /// The type of the task result. + /// The task to wait for. + /// The result of the completed task. + public static TResult Sync(this Task task) => task.ConfigureAwait(false).GetAwaiter().GetResult(); + } +} \ No newline at end of file