bitkid
10/01/2019, 11:15 AMimportFile(file) {client.submitFormWithBinaryData(bla)}
and a function importDirectory(dir) {dir.listFiles().forEach{importFile(it)}}
.. i want to upload the files in parallel, do some processing with the result returned from the server. best would be if i also had control over the level of concurrency (nr. of threads?)coroutineScope {
filesToUpload.map { async { importFile(it, repositoryId) } }.map { it.await() }.forEach { handleResult() }
}
Dominaezzz
10/01/2019, 12:15 PMawaitAll()
instead of map { it.await() }
.
You can read the doc to find out why it's better.bitkid
10/02/2019, 12:45 PMDominaezzz
10/02/2019, 12:48 PMbitkid
10/02/2019, 12:48 PMDominaezzz
10/02/2019, 12:48 PMbitkid
10/02/2019, 12:49 PMDominaezzz
10/02/2019, 12:50 PMbitkid
10/02/2019, 12:51 PMfilesToUpload.map { importFile(it, repositoryId) }.forEach { resp ->
when (resp.first) {
HttpStatusCode.OK -> File(statusDirectory, resp.third.nameWithoutExtension + ".ok").createNewFile()
else -> File(statusDirectory, resp.third.nameWithoutExtension + ".fail").writeText(resp.second)
}
}
coroutineScope {
filesToUpload.map { async(httpClient.coroutineContext) { importFile(it, repositoryId) } }.map { it.await() }.forEach { resp ->
when (resp.first) {
HttpStatusCode.OK -> File(statusDirectory, resp.third.nameWithoutExtension + ".ok").createNewFile()
else -> File(statusDirectory, resp.third.nameWithoutExtension + ".fail").writeText(resp.second)
}
}
}
Jorge R
10/03/2019, 11:10 AMbitkid
10/03/2019, 11:20 AM