Jebus_Chris
12/31/2022, 3:36 PMfun main() {
runBlocking {
launch {
values.forEach {
CoroutineScope(coroutineContext + <http://Dispatchers.IO|Dispatchers.IO>).launch {
val data = api.getData(it)
channel.send(data)
}
}
for (i in 1..values.size) {
val data = channel.receive()
CoroutineScope(coroutineContext + <http://Dispatchers.IO|Dispatchers.IO>).launch {
db.insert(data)
}
}
}.join()
}
}
jw
12/31/2022, 3:39 PMJebus_Chris
12/31/2022, 4:02 PMjw
12/31/2022, 4:25 PMJebus_Chris
12/31/2022, 10:48 PMColton Idle
01/01/2023, 3:45 PMWrite locks are exclusive so even with 1000 coroutines and 1000 threads executing perfectly in parallel it will be sequentialwait. maybe dumb question. but is that basically true of all SQL* databases? I never knew that it'd be sequential without anyway to write it. How do backend DBs keep up with tons of writes? 🤯
jw
01/01/2023, 5:02 PMColton Idle
01/01/2023, 5:53 PMjw
01/01/2023, 6:05 PMlouiscad
01/02/2023, 12:06 PMCoroutineScope(coroutineContext + <http://Dispatchers.IO|Dispatchers.IO>).launch
by just launch(<http://Dispatchers.IO|Dispatchers.IO>)
FYI.Jebus_Chris
01/02/2023, 3:11 PMcoroutineContext
then the main thread exits immediately. I think it’s something with parent child relationship.louiscad
01/02/2023, 3:35 PMJebus_Chris
01/02/2023, 3:39 PMsuspend fun
instead of main do I have to create a new coroutine scope?louiscad
01/02/2023, 8:36 PMcoroutineScope { }