Skip to content

Instantly share code, notes, and snippets.

@pjhjohn
Created April 6, 2018 06:51
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 pjhjohn/3dba34cdd4d1fee8285ebfc843e6e4c0 to your computer and use it in GitHub Desktop.
Save pjhjohn/3dba34cdd4d1fee8285ebfc843e6e4c0 to your computer and use it in GitHub Desktop.
package io.bitsound.apitestapp.utils
import io.reactivex.subjects.BehaviorSubject
import java.util.concurrent.atomic.AtomicInteger
class Counter {
val value: AtomicInteger = AtomicInteger()
val emitter: BehaviorSubject<Int> = BehaviorSubject.createDefault(value.toInt())
fun reset(): Counter {
value.set(0)
emitter.onNext(0)
return this
}
fun keep(): Unit {
emitter.onNext(value.get())
}
fun increase(): Unit {
val nextValue = value.incrementAndGet()
emitter.onNext(nextValue)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment