/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="DisposeAsync()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="DisposeAsync()"/> will not wait for the disposal to complete.</para> /// </remarks> public async ValueTask DisposeAsync() { var action = _context.TryGetAndUnset(); if (action == null) { return; } await action.InvokeAsync().ConfigureAwait(false); }
/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="DisposeAsync()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="DisposeAsync()"/> will wait for the disposal to complete.</para> /// </remarks> public async ValueTask DisposeAsync() { var context = _context.TryGetAndUnset(); if (context == null) { await _tcs.Task.ConfigureAwait(false); return; } try { await context.InvokeAsync().ConfigureAwait(false); } finally { _tcs.TrySetResult(null !); } }
/// <summary> /// Disposes this instance. /// </summary> /// <remarks> /// <para>If <see cref="DisposeAsync()"/> is called multiple times, only the first call will execute the disposal code. Other calls to <see cref="DisposeAsync()"/> will wait for the disposal to complete.</para> /// </remarks> public async ValueTask DisposeAsync() { var context = _context.TryGetAndUnset(); if (context == null) { await _tcs.Task.ConfigureAwait(false); return; } try { await context.InvokeAsync(); } finally { // TODO: document that exceptions are only observed by one disposer, not all. _tcs.TrySetResult(null); } }