Skip to content

Instantly share code, notes, and snippets.

@Kashif-E
Created December 6, 2021 11:17
Show Gist options
  • Save Kashif-E/0511c6c166664eb9bfffea465cc928cc to your computer and use it in GitHub Desktop.
Save Kashif-E/0511c6c166664eb9bfffea465cc928cc to your computer and use it in GitHub Desktop.
class UserRepository(private val responseHandler: ResponseHandler) {
suspend fun stimulateSocketTimeout() = flow {
//stimulate a network call
kotlinx.coroutines.delay(500)
emit(
//stimulate a failed network response
if (false) {
responseHandler
.handleSuccess("This should be api response")
} else {
Resource.Error(
CustomMessages.NO_INTERNET
)
}
)
}.flowOn(Dispatchers.IO).catch { e ->
e.printStackTrace()
emit(
Resource.Error(
CustomMessages.SOMETHING_WENT_WRONG
)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment