Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions Rx.NET/Source/src/System.Reactive/Disposables/DefaultDisposable.cs

This file was deleted.

27 changes: 25 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Disposables/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,33 @@ namespace System.Reactive.Disposables
/// </summary>
public static class Disposable
{
/// <summary>
/// Represents a disposable that does nothing on disposal.
/// </summary>
private sealed class EmptyDisposable : IDisposable
{
/// <summary>
/// Singleton default disposable.
/// </summary>
public static readonly EmptyDisposable Instance = new EmptyDisposable();

private EmptyDisposable()
{
}

/// <summary>
/// Does nothing.
/// </summary>
public void Dispose()
{
// no op
}
}

/// <summary>
/// Gets the disposable that does nothing when disposed.
/// </summary>
public static IDisposable Empty => DefaultDisposable.Instance;
public static IDisposable Empty => EmptyDisposable.Instance;

/// <summary>
/// Creates a disposable object that invokes the specified action when disposed.
Expand Down Expand Up @@ -50,7 +73,7 @@ internal static IDisposable GetValueOrDefault(ref IDisposable fieldRef)
var current = Volatile.Read(ref fieldRef);

return current == BooleanDisposable.True
? DefaultDisposable.Instance
? EmptyDisposable.Instance
: current;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public IDisposable Disposable

if (current == BooleanDisposable.True)
{
return DefaultDisposable.Instance; // Don't leak the sentinel value.
return Disposables.Disposable.Empty; // Don't leak the sentinel value.
}

return current;
Expand Down