| 82 | } |
| 83 | |
| 84 | public async ValueTask DisposeAsync() |
| 85 | { |
| 86 | if (Interlocked.CompareExchange(ref _disposed, 1, 0) == 0) |
| 87 | { |
| 88 | Exception? unsubscribeError = null; |
| 89 | |
| 90 | try |
| 91 | { |
| 92 | await _unsubscribe(default).ConfigureAwait(false); |
| 93 | } |
| 94 | catch (Exception ex) |
| 95 | { |
| 96 | _logger.Warn($"Wire unsubscribe failed during dispose: {ex.Message}"); |
| 97 | unsubscribeError = ex; |
| 98 | } |
| 99 | finally |
| 100 | { |
| 101 | _channel.Writer.TryComplete(); |
| 102 | |
| 103 | await _dispatchTask.ConfigureAwait(false); |
| 104 | |
| 105 | GC.SuppressFinalize(this); |
| 106 | } |
| 107 | |
| 108 | _handlerError?.Throw(); |
| 109 | _sourceError?.Throw(); |
| 110 | |
| 111 | if (unsubscribeError is not null) |
| 112 | { |
| 113 | ExceptionDispatchInfo.Capture(unsubscribeError).Throw(); |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | private async Task DispatchEventsAsync() |
| 119 | { |