private static void CompleteTask <T>(TaskCompletionSource <T> tcs, FfiResult result, Func <T> argFunc) { if (result.ErrorCode != 0) { tcs.SetException(result.ToException()); } else { tcs.SetResult(argFunc()); } }