1 import std.array : appender; 2 3 auto data = appender!(int[])(); 4 auto subject = new SubjectObject!int; 5 auto disposable = subject.subscribe(observerObject!(int)(data)); 6 assert(disposable !is null); 7 subject.put(0); 8 subject.put(1); 9 10 import std.algorithm : equal; 11 12 assert(equal(data.data, [0, 1])); 13 14 disposable.dispose(); 15 subject.put(2); 16 assert(equal(data.data, [0, 1]));
Represents an object that is both an observable sequence as well as an observer. Each notification is broadcasted to all subscribed observers.