Last active
September 11, 2016 16:23
-
-
Save ragdroid/4f3256fd27cfbc7652a9faa94b43225f to your computer and use it in GitHub Desktop.
Session Renew Problem - DroidconIN 2016
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
// Use concat and repeat to renew the session repeatedly | |
Observable<Session> getRenewedSession() { | |
Observable<Session> sessionObservable = | |
SessionManager.getCurrentSessionObservable() | |
.filter(new Func1<Session, Boolean>() { | |
@Override | |
public Boolean call(Session session) { | |
return session.isValid(); | |
} | |
}); | |
Observable<Session> renewSession = | |
SessionManager.getCurrentSessionObservable() | |
.flatMap(new Func1<Session, Observable<Session>>() { | |
@Override | |
public Observable<Session> call(Session session) { | |
return authService.renewSession(session.getSessionId()) | |
.repeatWhen( | |
new Func1<Observable<? extends Void>, Observable<?>>() { | |
@Override | |
public Observable<?> call( | |
Observable<? extends Void> observable) { | |
return observable.delay( | |
Session.EXPIRY_TIME_IN_MILLIS, | |
TimeUnit.MILLISECONDS); | |
} | |
}); | |
} | |
}); | |
return sessionObservable.concatWith(renewSession); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment