You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
package com.google.samples.apps.iosched.shared.domain
import com.google.samples.apps.iosched.shared.result.Result
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import timber.log.Timber
/**
* Executes business logic synchronously or asynchronously using Coroutines.
*/
abstract class UseCase<in P, R>(private val coroutineDispatcher: CoroutineDispatcher) {
/** Executes the use case asynchronously and returns a [Result].
*
* @return a [Result].
*
* @param parameters the input parameters to run the use case with
*/
suspend operator fun invoke(parameters: P): Result<R> {
return try {
// Moving all use case's executions to the injected dispatcher
// In production code, this is usually the Default dispatcher (background thread)
// In tests, this becomes a TestCoroutineDispatcher
withContext(coroutineDispatcher) {
execute(parameters).let {
Result.Success(it)
}
}
} catch (e: Exception) {
Timber.d(e)
Result.Error(e)
}
}
/**
* Override this to set the code to be executed.
*/
@Throws(RuntimeException::class)
protected abstract suspend fun execute(parameters: P): R
}
Note In above code withContext() required CouroutineContext . So it is giving error. Please let me know If am missing something.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi All,
I have an query in UseCase abstract class
Note In above code withContext() required CouroutineContext . So it is giving error. Please let me know If am missing something.
The text was updated successfully, but these errors were encountered: