Aaand next question, how is one supposed to use co...
# javascript
v
Aaand next question, how is one supposed to use coroutines in Kotlin/JS for node.js? You cannot do
runBlocking
as it does not exist for Kotlin/JS intentionally. Actually right now I just declared the
fun main()
as
suspend fun main()
and it seems to work properly. Just want to double-check whether this is the correct way. 🙂
t
GlobalScope.launch
can be more useful
v
Can you briefly explain why? I'm pretty new to coroutines
t
0. It can be called in any place 1. AFAIK You will have possibility to use custom context to sync coroutines
You can find it in
gradle-cache-...
:)
v
I can be called in any place
You mean the
GlobalScope.launch
? I fear I still don't understand. I'm calling a suspending function in
main
anyway if what you meant was, that it does not have to be in the entrypoint method but can be called deeper in the context Also, didn't I read that
GlobalScope.launch
will be like daemon threads and thus not hinder the process to quit in the coroutines docs? Or is this not relevant for JavaScript as it is a single-threaded language anyway?
1. AFAIK You will have possibility to use custom context to sync coroutines
I will probably not have multiple coroutines anyway, just some sequential code, but calling methods returning promises, so I use
.await()
on them
t
Thread is single :) If
suspend main
enough - good If you need sync group of promises - you can use
launch
lauch
- more 'clear' solution as for me, which can be simply copied in another function
v
Thanks, I think I'll stick with simply using
suspend
for now until I need more or change my mind. :-D
a
Ah, I remember why I never use
main()
— it gets run even when you’re running the tests. I have some extra Gradle taskage to produce script stubs to call top-level entry points
t