Created
June 8, 2023 04:42
-
-
Save u0705666/0602529026a694ecf501408c9f5b77ea to your computer and use it in GitHub Desktop.
concurrent suspend api calls
This file contains 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
@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