Skip to content

Instantly share code, notes, and snippets.

@romansl
romansl / toResultFlow.kt
Created May 31, 2019 12:56
Эта функция должна преобразовывать обычный flow во flow, значение которой обёрнуто в Result
fun <T> Flow<T>.toResultFlow(): Flow<Result<T>> {
return flow {
while (true) {
var fromDownstream = false
try {
collect {
try {
emit(Result.success(it))
} catch (e: Throwable) {
fromDownstream = true
package com.kaspersky.security_pulse_android.buisness.interactor
import com.kaspersky.security_pulse_android.buisness.repository.ILanguageRepository
import com.kaspersky.security_pulse_android.buisness.repository.ILoginRepository
import kotlinx.coroutines.experimental.async
import java.util.*
interface ILoginRepository {
// Если функции репорзитория всегда планируется запускать из другого треда,
// то разумно позаботиться о том, чтобы они сами для себя решали на каком
class CoroutineException(message: String) : RuntimeException(message)
class MyExceptionHandler(private val delegate: CoroutineExceptionHandler) :
AbstractCoroutineContextElement(CoroutineExceptionHandler), CoroutineExceptionHandler
{
override fun handleException(context: CoroutineContext, exception: Throwable) {
val ci = context[ContinuationInterceptor] as? DebugInterceptor
val ce = ci?.ce
val e = if (ce == null) {
@romansl
romansl / simple.kt
Last active December 17, 2017 17:34
Coroutine version.
class Rest {
suspend fun sendInstalledApps() {}
suspend fun updateCustomer() {}
suspend fun checkClientVersion() {}
suspend fun createOrUpdateDevice() {}
suspend fun refreshCustomerToken() {}
suspend fun getProfile() {}
}
suspend fun register(): Profile {
@romansl
romansl / VideoImageDownloader.java
Created December 28, 2015 08:50
VideoImageDownloader downloader for UIL
public class VideoImageDownloader extends BaseImageDownloader {
public AnyImageDownloader(Context context) {
super(context);
}
@Override
protected InputStream getStreamFromContent(final String imageUri, final Object extra) throws FileNotFoundException {
final ContentResolver res = context.getContentResolver();
final Uri uri = Uri.parse(imageUri);
{
"metadata": {
"name": "",
"signature": "sha256:4ce26b5cd56694a2c076f7ca84a3916fc131f662e0cf78c0406b2758203dc285"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [