doSubscribe

The helper for subscribe easier.

Examples

1 struct TestObservable
2 {
3     alias ElementType = int;
4 
5     auto subscribe(TObserver)(TObserver observer)
6     {
7         .put(observer, [0, 1, 2]);
8         return NopDisposable.instance;
9     }
10 }
11 
12 TestObservable observable;
13 int[] result;
14 observable.doSubscribe!(n => result ~= n);
15 assert(result.length == 3);
1 struct TestObserver
2 {
3     void put(int n)
4     {
5     }
6 }
7 
8 struct TestObservable1
9 {
10     alias ElementType = int;
11     Disposable subscribe(Observer!int observer)
12     {
13         return null;
14     }
15 }
16 
17 struct TestObservable2
18 {
19     alias ElementType = int;
20     Disposable subscribe(T)(T observer)
21     {
22         return null;
23     }
24 }
25 
26 TestObservable1 o1;
27 auto d0 = o1.doSubscribe((int n) {}, () {}, (Exception e) {});
28 auto d1 = o1.doSubscribe((int n) {}, () {});
29 auto d2 = o1.doSubscribe((int n) {}, (Exception e) {});
30 auto d3 = o1.doSubscribe((int n) {});
31 auto d4 = o1.doSubscribe(TestObserver());
32 TestObservable2 o2;
33 auto d5 = o2.doSubscribe((int n) {}, () {}, (Exception e) {});
34 auto d6 = o2.doSubscribe((int n) {}, () {});
35 auto d7 = o2.doSubscribe((int n) {}, (Exception e) {});
36 auto d8 = o2.doSubscribe((int n) {});
37 auto d9 = o2.doSubscribe(TestObserver());