withDisposed

  1. auto withDisposed(TDisposable disposable)
    template withDisposed(alias f)
    withDisposed
    (
    TDisposable
    )
    (
    auto ref TDisposable disposable
    )
    if (
    isDisposable!TDisposable
    )
  2. auto withDisposed(TDisposable disposable, void delegate() disposed)

Members

Functions

withDisposed
auto withDisposed(TDisposable disposable)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

import rx;

auto sub = new SubjectObject!int;
size_t putCount = 0;
size_t disposedCount = 0;

auto disposable = sub.doSubscribe!(_ => putCount++)
    .withDisposed!(() => disposedCount++);

sub.put(1);
disposable.dispose();

assert(putCount == 1);
assert(disposedCount == 1);
import rx;

auto sub = new SubjectObject!int;
size_t putCount = 0;

bool disposed = false;
alias traceDispose = withDisposed!(() => disposed = true);

auto disposable = traceDispose(sub.doSubscribe!(_ => putCount++));

sub.put(1);
sub.completed();

assert(putCount == 1);
assert(!disposed);
import rx;

auto sub = new SubjectObject!int;
size_t putCount = 0;

bool disposed = false;
alias traceDispose = withDisposed!(() => disposed = true);

auto disposable = traceDispose(sub.doSubscribe!(_ => putCount++));

sub.put(1);
disposable.dispose();

assert(putCount == 1);
assert(disposed);
import rx;

auto sub = new SubjectObject!int;
size_t putCount = 0;

bool disposed = false;
auto disposable = sub.doSubscribe!(_ => putCount++).withDisposed(() {
    disposed = true;
});

sub.put(1);
disposable.dispose();

assert(putCount == 1);
assert(disposed);
import rx;

auto sub = new SubjectObject!int;
size_t disposedCount = 0;

auto disposable = sub.doSubscribe!((int) {})
    .withDisposed!(() { disposedCount++; });

disposable.dispose();
disposable.dispose();

assert(disposedCount == 1);
import rx;

auto sub = new SubjectObject!int;
size_t putCount = 0;

bool disposed = false;
auto disposable = sub.doSubscribe!(_ => putCount++).withDisposed(() {
    disposed = true;
});

sub.put(1);
disposable.dispose();

assert(putCount == 1);
assert(disposed);
import rx;

auto sub = new SubjectObject!int;
size_t disposedCount = 0;

auto disposable = sub.doSubscribe!((int) {}).withDisposed(() {
    disposedCount++;
});

disposable.dispose();
disposable.dispose();

assert(disposedCount == 1);

Meta