Skip to content

Instantly share code, notes, and snippets.

View niqo01's full-sized avatar

Nicolas Milliard niqo01

  • CouchSurfing
  • San Francisco
View GitHub Profile
@niqo01
niqo01 / TestRx.java
Created March 28, 2014 21:17
Test code to automatically load from HTTP cache and refresh if response is stale from network if necesary
public static class TestRx {
public void test(){
Observable<String> getCacheHttpResource = Observable.from(new String[]{"Resource 1", "Resource 2 stale", "Resource 3"});
getCacheHttpResource.flatMap(new Func1<String, Observable<String>>() {
@Override public Observable<String> call(String s) {
return Observable.merge(deserialize(s), filter(s).flatMap(new Func1<String, Observable<? extends String>>() {
@Override public Observable<? extends String> call(String s) {
return refreshFromNetwork(s);
@niqo01
niqo01 / Controller.java
Last active December 11, 2015 12:48
Trying to figure out how to design Otto events properly with a classic refreshing use case. Notes that This is a naive Java implementation. This is not a working implementation.
@Singleton
public class Controller {
private final Bus mBus;
private boolean mIsRefreshing;
private Exception mLastRefreshException;
@Inject
public Controller(Bus bus) {