From 41db75b183e7add5e2bb375e4a117f6d8f459424 Mon Sep 17 00:00:00 2001 From: TekH Date: Fri, 16 Jan 2026 11:03:53 +0100 Subject: [PATCH] Add TaskSyncExtensions for sync Task execution (.NET FW) Introduced TaskSyncExtensions class with Sync extension methods to allow synchronous execution of Task and Task instances. This enables blocking on async code and is conditionally compiled for .NET Framework builds. --- src/ReC.Client/TaskSyncExtensions.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/ReC.Client/TaskSyncExtensions.cs 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