ubu
10/25/2019, 11:30 AMoverride suspend fun createAccount(
name: String,
avatarPath: String?
) : AccountEntity {
Timber.d("Thread: ${Thread.currentThread().name}")
return service.createAccount(name, avatarPath).let { response ->
AccountEntity(
id = response.id,
name = response.name,
avatar = response.avatar.toEntity()
)
}
}
I launch inside ViewModelScope
. Any help will be appreciated!diesieben07
10/25/2019, 11:31 AMsuspend
modifier only means "this function can suspend". It does not say anything about on which thread it will run.ubu
10/25/2019, 11:33 AMabstract class BaseUseCase<out Type, in Params> where Type : Any {
abstract suspend fun run(params: Params): Either<Throwable, Type>
open operator fun invoke(
scope: CoroutineScope,
params: Params,
onResult: (Either<Throwable, Type>) -> Unit = {}
) {
val backgroundJob = scope.async { run(params) }
scope.launch { onResult(backgroundJob.await()) }
}
object None
}
invoke()
gets ViewModelScope
diesieben07
10/25/2019, 11:36 AMlouiscad
10/25/2019, 12:36 PMgildor
10/25/2019, 12:38 PMgildor
10/25/2019, 12:39 PMgildor
10/25/2019, 12:40 PMubu
11/06/2019, 12:44 PM