Skip to content

Instantly share code, notes, and snippets.

@lookashc
Created December 21, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lookashc/a3d95c8de3f049cca52ec1e1dbaabc01 to your computer and use it in GitHub Desktop.
Save lookashc/a3d95c8de3f049cca52ec1e1dbaabc01 to your computer and use it in GitHub Desktop.
medium-feature-toggles-gist6
abstract class FeatureToggleCompanion<T : Any>(
featureToggleSet: Set<@JvmSuppressWildcards FeatureToggle<*>>,
associatedFeature: Feature<T>
) {
protected val toggle = featureToggleSet.first { it.feature == associatedFeature }
val feature = toggle.feature
val featureValue = toggle.value
protected abstract fun executeUpdate(value: T): Completable
fun update(value: T): Disposable =
executeUpdate(value)
.subscribeOn(Schedulers.io())
.doOnComplete { toggle.value = value }
.subscribe({}, Timber::e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment