private static void CompleteTask <T>(TaskCompletionSource <T> tcs, FfiResult result, Func <T> argFunc) { if (result.ErrorCode != 0) { Task.Run(() => { tcs.SetException(result.ToException()); }); } else { var arg = argFunc(); Task.Run(() => { tcs.SetResult(arg); }); } }
public static void CompleteTask(IntPtr userData, FfiResult result) => CompleteTask(userData, result, () => true);
public static void CompleteTask <T>(IntPtr userData, FfiResult result, Func <T> argFunc) { var tcs = FromHandlePtr <TaskCompletionSource <T> >(userData); CompleteTask(tcs, result, argFunc); }