Skip to content

'Forget' extensions on ValueTask need to fake an await #556

@sharwell

Description

@sharwell

Bug description

ValueTask instances can be backed by pooled objects. If these tasks are not awaited, the pooled objects can get discarded, negatively impacting application efficiency.

Repro steps

Expected behavior

The Forget extension methods behave as though the task is awaited. @stephentoub may be able to help identify the most efficient approach here.

Actual behavior

The task is not awaited.

/// <summary>
/// Consumes a task and doesn't do anything with it. Useful for fire-and-forget calls to async methods within async methods.
/// </summary>
/// <param name="task">The task whose result is to be ignored.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "task")]
public static void Forget(this ValueTask task)
{
}
/// <summary>
/// Consumes a task and doesn't do anything with it. Useful for fire-and-forget calls to async methods within async methods.
/// </summary>
/// <typeparam name="T">The type of value produced by the <paramref name="task"/>.</typeparam>
/// <param name="task">The task whose result is to be ignored.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "task")]
public static void Forget<T>(this ValueTask<T> task)
{
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions