atomicDispose

void
atomicDispose
(
T
)
(
ref shared(T) disposable
)
if (
(
is(T == class) ||
is(T == interface)
)
)

Examples

size_t count;
class MyDisposable
{
    void dispose()
    {
        count++;
    }
}

auto disposable = cast(shared) new MyDisposable;

.atomicDispose(disposable);
assert(count == 1);
assert(disposable is null);

.atomicDispose(disposable);
assert(count == 1);
assert(disposable is null);
size_t count;
class MyDisposable : Disposable
{
    void dispose()
    {
        count++;
    }
}

shared(Disposable) disposable = cast(shared) new MyDisposable;

.atomicDispose(disposable);
assert(count == 1);
assert(disposable is null);

.atomicDispose(disposable);
assert(count == 1);
assert(disposable is null);
class MyDisposable
{
    void dispose()
    {
    }
}

shared(MyDisposable) disposable1 = null;
.atomicDispose(disposable1);
shared(Disposable) disposable2 = null;
.atomicDispose(disposable2);

Meta