Last active
August 29, 2015 14:21
-
-
Save sohamtriveous/3b4764ce8af0af77f078 to your computer and use it in GitHub Desktop.
RxJava wrappers for get/put in Reservoir
This file contains hidden or 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
package com.farmily.android.store; | |
import android.content.Context; | |
import com.anupcowkur.reservoir.Reservoir; | |
import rx.Observable; | |
import rx.Subscriber; | |
import rx.schedulers.Schedulers; | |
/** | |
* Created by sohammondal on 26/05/15. | |
*/ | |
public class ObjectStore { | |
public static <T> Observable<T> get(final String key, final Class<T> classOfT) { | |
Observable<T> observable = Observable.create(new Observable.OnSubscribe<T>() { | |
@Override | |
public void call(Subscriber<? super T> subscriber) { | |
try { | |
T t = Reservoir.get(key, classOfT); | |
subscriber.onNext(t); | |
subscriber.onCompleted(); | |
} catch (Exception exception) { | |
subscriber.onError(exception); | |
subscriber.onCompleted(); | |
} | |
} | |
}).subscribeOn(Schedulers.io()); | |
return observable; | |
} | |
public static Observable<Boolean> put(String key, Object object) { | |
Observable<Boolean> observable = Observable.create(new Observable.OnSubscribe<Boolean>() { | |
@Override | |
public void call(Subscriber<? super Boolean> subscriber) { | |
try { | |
Reservoir.put(key, object); | |
subscriber.onNext(true); | |
subscriber.onCompleted(); | |
} catch (Exception exception) { | |
subscriber.onError(exception); | |
subscriber.onCompleted(); | |
} | |
} | |
}).subscribeOn(Schedulers.io()); | |
return observable; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment