Skip to content

Instantly share code, notes, and snippets.

View UploadFilesUseCase.kt
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext
class UploadFilesUseCase : BaseBusyObservable<UploadFilesUseCase.Listener>() {
interface Listener {
fun onFilesUploaded()
View UseCase.kt
class UploadFilesUseCase(
private val schedulerProvider: SchedulerProvider,
private val httpManager: HttpManager
) {
private var operation: Completable? = null
fun uploadFiles(): Completable = synchronized(this) {
?: (doUploadFiles()
techyourchance /
Created Dec 21, 2019
Base class for Java Observable which needs to be aware of whether it's "busy" and expose this information to its clients
public abstract class BaseBusyObservable<LISTENER_CLASS> extends BaseObservable<LISTENER_CLASS> {
private final AtomicBoolean mIsBusy = new AtomicBoolean(false);
public final boolean isBusy() {
return mIsBusy.get();
* Atomically assert not busy and become busy
techyourchance /
Last active May 8, 2020
Base class for Java Observable
public abstract class BaseObservable<LISTENER_CLASS> {
private final Object MONITOR = new Object();
private final Set<LISTENER_CLASS> mListeners = new HashSet<>();
public void registerListener(LISTENER_CLASS listener) {
synchronized (MONITOR) {
boolean hadNoListeners = mListeners.size() == 0;
georgegach /
Last active Jul 18, 2021 — forked from SangsooNam/
Script to deploy a target directory to `gh-pages` branch and force server-side cache to update
build_command() {
jekyll build
echo -e "\033[0;32mDeleting existing $branch...\033[0m"
git push origin --delete $branch
git branch -D $branch
objcode / ConcurrencyHelpers.kt
Last active Jul 21, 2021
Helpers to control concurrency for one shot requests using Kotlin coroutines.
View ConcurrencyHelpers.kt
import kotlinx.coroutines.CoroutineStart.LAZY
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.yield
import java.util.concurrent.atomic.AtomicReference
import kotlin.DeprecationLevel.ERROR
View CoroutinesTestRule.kt
class CoroutinesTestRule(
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
) : TestWatcher() {
override fun starting(description: Description?) {
View FragmentBindingModule.kt
abstract class FragmentBindingModule {
abstract fun bindFragmentFactory(factory: FragmentInjectionFactory): FragmentFactory
abstract fun bindMainFragment(fragment: MainFragment): Fragment
ZakTaccardi / ExampleActivity.kt
Last active May 13, 2021
Example MVI Implementation with Coroutines
View ExampleActivity.kt
import kotlinx.coroutines.experimental.CoroutineScope
class ExampleActivity : Activity(), CoroutineScope by CoroutineScope(Dispatchers.Main) {
override fun onCreate(savedInstanceState: Bundle?)
val ui = Ui(this) // bind views, etc
SangsooNam /
Created Jan 6, 2019
Script to deploy a target directory to `gh-pages` branch.
build_command() {
jekyll build
echo -e "\033[0;32mDeleting old content...\033[0m"
rm -rf $directory