Skip to content

Instantly share code, notes, and snippets.

@jsaund
Created February 23, 2017 08:47
Show Gist options
  • Select an option

  • Save jsaund/7ac7a5bb0d3e65d6f207c35df3f5ba1b to your computer and use it in GitHub Desktop.

Select an option

Save jsaund/7ac7a5bb0d3e65d6f207c35df3f5ba1b to your computer and use it in GitHub Desktop.
Demonstrates converting a synchronous operation, such as committing to shared preferences, to a reactive one by using the fromCallable static helper.
public Observable<Boolean> enablePushNotifications(boolean enable) {
return Observable.fromCallable(() -> sharedPrefs
.edit()
.putBoolean(KEY_PUSH_NOTIFICATIONS_PREFS, enable)
.commit());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment