Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivityProcessor should implement IAsyncDisposable for netstandard2.1? #982

Closed
eddynaka opened this issue Aug 3, 2020 · 1 comment
Closed
Labels
enhancement New feature or request pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Comments

@eddynaka
Copy link
Contributor

eddynaka commented Aug 3, 2020

After the PR #975, ActivityProcessor will implement IDisposable. With netstandard2.1, we can also implement IAsyncDisposable.

Below one example that @pcwiese sent me:

public class TestClass : IDisposable
#if NETSTANDARD2_1
, IAsyncDisposable
#endif
{
/// <inheritdoc/>
    public void Dispose()
    {
        if (Interlocked.CompareExchange(ref this.disposed, 1, 0) == 1)
        {
            return;
        }

        this.Dispose(true);
        GC.SuppressFinalize(this);
    }

#if NETSTANDARD2_1
    /// <inheritdoc/>
    public async ValueTask DisposeAsync()
    {
        if (Interlocked.CompareExchange(ref this.disposed, 1, 0) == 1)
        {
            return;
        }

        // see https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync#the-disposeasync-method
        // Perform async cleanup.
        await this.DisposeAsyncCore().ConfigureAwait(false);

        // Dispose of managed resources.
        this.Dispose(false);

        // Suppress finalization.
        GC.SuppressFinalize(this);
    }
#endif

    /// <summary>
    /// Releases unmanaged and - optionally - managed resources.
    /// </summary>
    /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
    protected virtual void Dispose(bool disposing)
    {
    }

#if NETSTANDARD2_1
    /// <summary>
    /// Releases unmanaged and - optionally - managed resources asynchronously.
    /// </summary>
    /// <returns>a ValueTask</returns>
    protected virtual ValueTask DisposeAsyncCore()
    {
        return default;
    }
#endif
}

cc: @reyang

@eddynaka eddynaka added the question Further information is requested label Aug 3, 2020
@eddynaka eddynaka mentioned this issue Aug 3, 2020
2 tasks
@reyang reyang added pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package enhancement New feature or request priority:p2 and removed question Further information is requested labels Aug 3, 2020
@martinjt
Copy link
Member

Doesn't seem like there is demand for this, so I'm going to close, feel free to reopen if you think this is still required.

@martinjt martinjt closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

No branches or pull requests

3 participants