bitkid
10/01/2019, 11:15 AMbitkid
10/01/2019, 11:19 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?)bitkid
10/01/2019, 11:20 AMbitkid
10/01/2019, 11:32 AMbitkid
10/01/2019, 11:32 AMcoroutineScope {
filesToUpload.map { async { importFile(it, repositoryId) } }.map { it.await() }.forEach { handleResult() }
}
bitkid
10/01/2019, 11:32 AMDominaezzz
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 PMbitkid
10/02/2019, 12:46 PMbitkid
10/02/2019, 12:47 PMbitkid
10/02/2019, 12:47 PMbitkid
10/02/2019, 12:47 PMDominaezzz
10/02/2019, 12:48 PMbitkid
10/02/2019, 12:48 PMDominaezzz
10/02/2019, 12:48 PMbitkid
10/02/2019, 12:49 PMbitkid
10/02/2019, 12:49 PMDominaezzz
10/02/2019, 12:50 PMbitkid
10/02/2019, 12:51 PMbitkid
10/02/2019, 12:55 PMbitkid
10/02/2019, 12:57 PMbitkid
10/02/2019, 12:57 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)
}
}
bitkid
10/02/2019, 12:57 PMbitkid
10/02/2019, 12:58 PMcoroutineScope {
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)
}
}
}
bitkid
10/02/2019, 12:58 PMbitkid
10/02/2019, 12:59 PMbitkid
10/02/2019, 12:59 PMbitkid
10/02/2019, 12:59 PMbitkid
10/02/2019, 1:00 PMbitkid
10/02/2019, 2:27 PMJorge R
10/03/2019, 11:10 AMJorge R
10/03/2019, 11:10 AMJorge R
10/03/2019, 11:12 AMJorge R
10/03/2019, 11:17 AMbitkid
10/03/2019, 11:20 AMbitkid
10/03/2019, 12:26 PM