-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from energyworldnet/fix-stream-disposal
Fix incompatibility w/ Portable.BouncyCastle 1.9.0
- Loading branch information
Showing
3 changed files
with
282 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
|
||
namespace PgpCore | ||
{ | ||
/// <seealso href="https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/Disposables/CompositeDisposable.cs"> | ||
/// Simplified adaptation from System.Reactive. | ||
/// </seealso> | ||
internal sealed class CompositeDisposable : IDisposable | ||
{ | ||
private readonly ConcurrentQueue<IDisposable> _disposables = new ConcurrentQueue<IDisposable>(); | ||
|
||
public void Add(IDisposable disposable) | ||
{ | ||
if (disposable == null) | ||
throw new ArgumentNullException(nameof(disposable)); | ||
|
||
_disposables.Enqueue(disposable); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
while (_disposables.TryDequeue(out IDisposable disposable)) | ||
disposable.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace PgpCore | ||
{ | ||
internal static class DisposableExtensions | ||
{ | ||
/// <seealso href="https://github.com/reactiveui/ReactiveUI/blob/main/src/ReactiveUI/Mixins/DisposableMixins.cs#L28"> | ||
/// Adapted from ReactiveUI. | ||
/// </seealso> | ||
public static T DisposeWith<T>(this T @this, CompositeDisposable disposables) | ||
where T : IDisposable | ||
{ | ||
if (@this == null) | ||
throw new ArgumentNullException(nameof(@this)); | ||
if (disposables == null) | ||
throw new ArgumentNullException(nameof(disposables)); | ||
|
||
disposables.Add(@this); | ||
return @this; | ||
} | ||
} | ||
} |
Oops, something went wrong.