Created
April 6, 2018 06:51
-
-
Save pjhjohn/3dba34cdd4d1fee8285ebfc843e6e4c0 to your computer and use it in GitHub Desktop.
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 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