Skip to content

Instantly share code, notes, and snippets.

Victor Mykhailiv vitoksmile

View GitHub Profile
@vitoksmile
vitoksmile / CoolJob.kt
Last active Dec 11, 2018
Wrapper over Coroutine Job to catch exception
View CoolJob.kt
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
/**
* Launch new block in coroutine and invoke callbacks after execution
*
* @param onComplete Called when launch was success
* @param onError Called when launch had an exception
* @param onFinally Called after launch (ignore result)
@vitoksmile
vitoksmile / DeferredX.kt
Created Nov 1, 2018
Extension to Deferred to await values without need catch Exception
View DeferredX.kt
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.Dispatchers
/**
* Coroutine dispatcher that is confined to the Main thread operating with UI objects
*/
val UI = Dispatchers.Main
/**
@vitoksmile
vitoksmile / KoinPropertyDelegate.kt
Last active Oct 26, 2018
Saving values to Koin's property with delegating
View KoinPropertyDelegate.kt
import org.koin.standalone.KoinComponent
import org.koin.standalone.getKoin
import kotlin.reflect.KProperty
class KoinPropertyDelegate<R, T : Any>(private val key: String, private val default: T) :
KoinComponent {
operator fun getValue(thisRef: R, property: KProperty<*>): T {
return getKoin().getProperty<Any>(key, default) as T
}
@vitoksmile
vitoksmile / KoinUtils.kt
Created Oct 26, 2018
Using dependency injections by Koin without implementing KoinComponent
View KoinUtils.kt
import org.koin.core.KoinContext
import org.koin.core.parameter.ParameterDefinition
import org.koin.core.parameter.emptyParameterDefinition
import org.koin.core.scope.Scope
import org.koin.standalone.StandAloneContext
/**
* inject lazily given dependency
* @param name - bean canonicalName
* @param parameters - injection parameters
You can’t perform that action at this time.