CompositeDisposable

Constructors

this
this(Disposable[] disposables)

Members

Functions

clear
void clear()
count
size_t count()
dispose
void dispose()
insert
void insert(Disposable item)
remove
bool remove(Disposable item)

Inherited Members

From Disposable

dispose
void dispose()

Examples

auto d1 = new SingleAssignmentDisposable;
auto d2 = new SerialDisposable;
auto d = new CompositeDisposable(d1, d2);
d.dispose();
assert(d.count == 0);
auto composite = new CompositeDisposable;
auto disposed = false;
auto inner = new AnonymousDisposable({ disposed = true; });
composite.insert(inner);
composite.dispose();
assert(disposed);
auto composite = new CompositeDisposable;
size_t _count = 0;
auto inner = new AnonymousDisposable({ _count++; });
composite.insert(inner);
composite.clear(); // clear items and dispose all
assert(_count == 1);

composite.clear();
assert(_count == 1);
auto composite = new CompositeDisposable;
composite.dispose();

auto disposed = false;
auto inner2 = new AnonymousDisposable({ disposed = true; });
composite.insert(inner2);
assert(disposed);
auto composite = new CompositeDisposable;
bool disposed = false;
auto disposable = new AnonymousDisposable({ disposed = true; });
composite.insert(disposable);
composite.remove(disposable);
composite.dispose();
assert(!disposed);
auto composite = new CompositeDisposable;
Disposable[] ds;
size_t disposedCount = 0;
foreach (_; 0 .. 100)
{
    auto temp = new AnonymousDisposable({ disposedCount++; });
    composite.insert(temp);
    ds ~= temp;
}
foreach (i; 0 .. 80)
{
    composite.remove(ds[i]);
}
assert(composite.count == 20);
composite.dispose();
assert(composite.count == 0);
assert(disposedCount == 20);
auto composite = new CompositeDisposable;
auto disposed = false;
auto item = new AnonymousDisposable({ disposed = true; });
composite.insert(item);
composite.remove(item);
composite.clear();
assert(!disposed);

Meta