Created
April 28, 2015 13:47
-
-
Save juanpavergara/5bb96f157d9dde4099ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List; | |
import rx.Observable; | |
import rx.subjects.PublishSubject; | |
public class ObservableListExample { | |
public static class ObservableList<T> { | |
protected final List<T> list; | |
protected final PublishSubject<T> onAdd; | |
public ObservableList() { | |
this.list = new ArrayList<T>(); | |
this.onAdd = PublishSubject.create(); | |
} | |
public void add(T value) { | |
list.add(value); | |
onAdd.onNext(value); | |
} | |
public Observable<T> getObservable() { | |
return onAdd; | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
ObservableList<Integer> olist = new ObservableList<>(); | |
olist.getObservable().subscribe(System.out::println); | |
olist.add(1); | |
Thread.sleep(1000); | |
olist.add(2); | |
Thread.sleep(1000); | |
olist.add(3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment