ursus
02/02/2023, 6:48 PMcoroutineScope {
launch { foo() }
bar()
}
coroutineScope {
launch { foo() }
launch { bar() }
}
are these equivalent?Big Chungus
02/02/2023, 6:49 PMjw
02/02/2023, 6:51 PMBig Chungus
02/02/2023, 6:52 PMjw
02/02/2023, 6:54 PMJacob
02/02/2023, 6:55 PMjw
02/02/2023, 6:55 PMlaunch
is "post this to a queue" then if you don't post bar
but instead execute it synchronously after posting foo
it will run firstursus
02/02/2023, 6:57 PMcoroutineScope
will await them both, then it doesn't matter/first has less overhead?Big Chungus
02/02/2023, 6:57 PMkevin.cianfarini
02/02/2023, 6:58 PMJacob
02/02/2023, 6:58 PMyield()
then they might appear to be in the same orderephemient
02/02/2023, 6:58 PMlaunch { foo() }
, it is not specified how much of foo
has run before the next statement in the callerjw
02/02/2023, 6:59 PMyield
, but yes they might be the same sometimesephemient
02/02/2023, 7:00 PMlaunch(start = CoroutineStart.UNDISPATCHED) { foo() }
you can say that up to the first suspension point in foo()
has executed, I believelaunch(start = CoroutineStart.LAZY) { foo() }
you should be able to say that none of it has executedursus
02/02/2023, 7:01 PMio
dispatcher, then what is more idiomatic, if you only care that they're executed in parallel a nd coroutineScope awaits both of themjw
02/02/2023, 7:01 PMfoo
will always run before bar
Jacob
02/02/2023, 7:03 PMephemient
02/02/2023, 7:03 PMursus
02/02/2023, 7:07 PMcoroutineScope {
launch { syncInvoices() }
launch { syncMessages() }
}
probably the dual launch makes it more apparent that they're both going in parallel?Casey Brooks
02/02/2023, 7:08 PMlaunch
blocksephemient
02/02/2023, 7:08 PMlaunch
ursus
02/02/2023, 7:10 PMcoroutineScope {
launch { syncInvoices() }
syncMessages()
}
says "syncMessages after enqueueing syncInvoices coroutine" ?ephemient
02/02/2023, 7:18 PMgildor
02/03/2023, 6:05 AM