Is there any alternative to calls `async {` builde...
# orbit-mvi
m
Is there any alternative to calls
async {
builder inside
intent {
? Code in 🧵
Our current code:
Copy code
fun uploadFile(uploadsBody: List<Pair<String, UploadBody>?>) = intent {
        viewModelScope.launch {
            val listDeferred = mutableListOf<Deferred<UploadFileModel>>()
            uploadsBody.forEach { pair ->
                if (pair != null) {
                    val deferred = async {
                        val result = uploadPhotoUseCase(pair.second).catch {
                            throw CancellationException("Gagal unggah berkas", it)
                        }.first()
                        return@async UploadFileModel(pair.first, pair.second.file, result)
                    }
                    listDeferred.add(deferred)
                    runCatching {
                        reduce {
                            state.copy(isLoadingButton = true)
                        }
                        listDeferred.awaitAll()
                    }.onSuccess { uploadedFiles ->
                        reduce {
                            state.copy(isLoadingButton = false)
                        }
                        postSideEffect(
                             sideEffect = FormApprovalEffect.SuccessUploadFiles(uploadedFiles),
                        )
                    }.onFailure { throwable ->
                        val error = errorDictionaryUseCase(throwable)
                        reduce {
                            state.copy(isLoadingButton = false)
                        }
                        postSideEffect(
                            sideEffect = FormApprovalEffect.ShowErrorGeneral(
                                summary = error.summary,
                                detail = error.detail,
                            )
                        )
                    }
                }
            }
        }
    }
but, based on previous thread in here, any other suggestion to improve it?
what we understand so far:
Copy code
fun uploadFile(uploadsBody: List<Pair<String, UploadBody>?>) = intent {
        coroutineScope {
           launch(Dispather.Default) {
              // calls the `async` builder in here(?)
           }
        }
    }
based on: https://kotlinlang.slack.com/archives/CPM6UMD2P/p1623832989030700?thread_ts=1623832162.029000&amp;cid=CPM6UMD2P