doSubscribe

The helper for subscribe easier.

  1. auto doSubscribe(TObservable observable, void delegate(E) doPut, void delegate() doCompleted, void delegate(Exception) doFailure)
    doSubscribe
    (
    TObservable
    E
    )
    (
    auto ref TObservable observable
    ,
    void delegate
    (
    E
    )
    doPut
    ,
    void delegate
    ()
    doCompleted
    ,
    void delegate
    (
    Exception
    )
    doFailure
    )
  2. auto doSubscribe(TObservable observable, void delegate(E) doPut, void delegate() doCompleted)
  3. auto doSubscribe(TObservable observable, void delegate(E) doPut, void delegate(Exception) doFailure)
  4. auto doSubscribe(TObservable observable)
  5. auto doSubscribe(TObservable observable, TObserver observer)

Examples

struct TestObservable
{
    alias ElementType = int;

    auto subscribe(TObserver)(TObserver observer)
    {
        .put(observer, [0, 1, 2]);
        return NopDisposable.instance;
    }
}

TestObservable observable;
int[] result;
observable.doSubscribe!(n => result ~= n);
assert(result.length == 3);
struct TestObserver
{
    void put(int n)
    {
    }
}

struct TestObservable1
{
    alias ElementType = int;
    Disposable subscribe(Observer!int observer)
    {
        return null;
    }
}

struct TestObservable2
{
    alias ElementType = int;
    Disposable subscribe(T)(T observer)
    {
        return null;
    }
}

TestObservable1 o1;
auto d0 = o1.doSubscribe((int n) {}, () {}, (Exception e) {});
auto d1 = o1.doSubscribe((int n) {}, () {});
auto d2 = o1.doSubscribe((int n) {}, (Exception e) {});
auto d3 = o1.doSubscribe((int n) {});
auto d4 = o1.doSubscribe(TestObserver());
TestObservable2 o2;
auto d5 = o2.doSubscribe((int n) {}, () {}, (Exception e) {});
auto d6 = o2.doSubscribe((int n) {}, () {});
auto d7 = o2.doSubscribe((int n) {}, (Exception e) {});
auto d8 = o2.doSubscribe((int n) {});
auto d9 = o2.doSubscribe(TestObserver());

Meta