Created
December 6, 2021 11:17
-
-
Save Kashif-E/0511c6c166664eb9bfffea465cc928cc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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