everrise-ecosystem_EverStats/src/Helpers/ValueTaskExtensions.cs
// Copyright (c) EverRise Pte Ltd. All rights reserved.

using System.IO.Pipelines;
using System.Runtime.CompilerServices;

namespace System.Threading.Tasks;
public static class ValueTaskExtensions
{
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static Task GetAsTask(this in ValueTask<FlushResult> valueTask)
    {
        if (valueTask.IsCompletedSuccessfully)
        {
            // Signal consumption to the IValueTaskSource
            valueTask.GetAwaiter().GetResult();
            return Task.CompletedTask;
        }
        else
        {
            return valueTask.AsTask();
        }
    }
}
