kd
01/29/2019, 7:15 PMAllan Wang
01/29/2019, 7:15 PMAllan Wang
01/29/2019, 7:16 PMkd
01/29/2019, 7:17 PMAllan Wang
01/29/2019, 7:19 PMAllan Wang
01/29/2019, 7:20 PMyield()
, which allows other coroutines to run and will cancel if the job is cancelledghedeon
01/29/2019, 7:21 PMCoroutineScope
all the way down, from UI to Data... The code starts looking really strange tho.. If you're lucky to have only coroutineScope{}
use cases than its cleaner and suspend
is enough.kd
01/29/2019, 7:21 PMgildor
01/30/2019, 1:31 AMDavide Giuseppe Farella
01/30/2019, 7:19 AMsuspend fun doJob() { }
* same as above, but I need that function to do some works asynchronously suspend fun doJob() = coroutineScope { }
* I wanna launch something and don't wait for it to complete fun CoroutineScope.doJob() = launch { }
gildor
01/30/2019, 7:21 AMfun doJob(scope: CoroutineScope) = scope.launch { }
But launch probably is a bad example, I don’t see use cases for launch. Only valid case what I see it’s actor{}
or produce{}
Davide Giuseppe Farella
01/30/2019, 7:23 AMlaunch
seems to fit my use case, I'll take a look at those apis 🍻gildor
01/30/2019, 7:23 AMgildor
01/30/2019, 7:24 AMgildor
01/30/2019, 7:24 AMfun CoroutineScope.doJob() = launch { }
Davide Giuseppe Farella
01/30/2019, 7:24 AMgildor
01/30/2019, 7:25 AMDavide Giuseppe Farella
01/30/2019, 7:26 AMoperator fun CoroutineScope.invoke(
channels: SendChannel<IChannel>,
groups: SendChannel<ChannelGroup>,
errors: SendChannel<ChannelError>
) = launch { /* do smtng and deliver to Channels */ }
Davide Giuseppe Farella
01/30/2019, 7:27 AMlaunch
since I don't want to wait for this function tu complete, once is calledgildor
01/30/2019, 7:29 AMgildor
01/30/2019, 7:30 AMgildor
01/30/2019, 7:30 AMproduce{}
for thisgildor
01/30/2019, 7:30 AMDavide Giuseppe Farella
01/30/2019, 7:37 AMproduce
or my function?gildor
01/30/2019, 7:37 AMDavide Giuseppe Farella
01/30/2019, 7:40 AMparser.run { this@scope( /* channels */ ) }
. Still working on it 😁Davide Giuseppe Farella
01/30/2019, 7:42 AMlaunch { parser( /* channels */ ) }
anyway I'm goin off topic 😋 I already posted that question on #general and ghideon told me that already thousands of people made the same question 😁gildor
01/30/2019, 7:44 AMgildor
01/30/2019, 7:48 AMIt would be great to haveBut you can have such APIlaunch { parser( /* channels */ ) }
Davide Giuseppe Farella
01/30/2019, 7:49 AMkd
01/30/2019, 3:10 PMDavide Giuseppe Farella
01/30/2019, 3:19 PMrunBlocking
, AFAIK it's the best ( only? ) waykd
01/30/2019, 3:27 PMgildor
01/30/2019, 4:34 PMgildor
01/30/2019, 4:36 PM