Skip to content

Instantly share code, notes, and snippets.

@u0705666
Created June 8, 2023 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u0705666/0602529026a694ecf501408c9f5b77ea to your computer and use it in GitHub Desktop.
Save u0705666/0602529026a694ecf501408c9f5b77ea to your computer and use it in GitHub Desktop.
concurrent suspend api calls
@Inject lateinit var suspendApi: SuspendApi
...
view!!.showTransparentLoading()
shownScope.launch {
val assetCategoriesResultDeferred = async{suspendApi.getAssetCategories()}
val categorizedAssetDeferred = async{suspendApi.getCategorizedAssets()}
val assetCategoriesResult = assetCategoriesResultDeferred.await()
val categorizedAssetsResult = categorizedAssetDeferred.await()
if (assetCategoriesResult is ApiResult.Success && categorizedAssetsResult is ApiResult.Success) {
assetCategoryList = assetCategoriesResult.data.assetCategories
fullAssetList = categorizedAssetsResult.data.categorizedAssets
view!!.setupCategoryView(getCategoryListItem(assetCategoryList!!, fullAssetList!!))
view!!.hideLoadingAndErrorStates()
} else {
toaster.showShortErrorToast("api error to get category or assets list")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment