Rohit Surwase
10/30/2018, 4:12 AMHandlerThread + Looper
? I tried and it worked for limited use case but not sure about generic use case. I feel it is not a good practice and will not work for all cases? Is it?gildor
10/30/2018, 5:19 AMgildor
10/30/2018, 5:19 AMRohit Surwase
10/30/2018, 5:48 AMService
usually, we create our own worker thread + looper to execute long running tasks. What about using coroutines instead of our usual approach?Rohit Surwase
10/30/2018, 5:52 AMgildor
10/30/2018, 7:16 AMRohit Surwase
10/30/2018, 7:19 AMgildor
10/30/2018, 7:21 AM<http://Dispatchers.IO|Dispatchers.IO>
threads will be reusedgildor
10/30/2018, 7:22 AMgildor
10/30/2018, 7:22 AMRohit Surwase
10/30/2018, 7:26 AMgildor
10/30/2018, 7:30 AMRohit Surwase
11/01/2018, 5:13 AMService
, IntentService
using Coroutines
. https://gist.github.com/RohitSurwase/6a31ecdbcdc7e8712a6b517e305d7308
I would really appreciate if you could have a look at it and let me know your thoughts. Though I have fewer doubts about it, I would ask it later. Thanks!gildor
11/01/2018, 5:15 AMgildor
11/01/2018, 5:15 AMRohit Surwase
11/01/2018, 5:18 AMRohit Surwase
11/01/2018, 5:18 AMgildor
11/01/2018, 5:19 AMgildor
11/01/2018, 5:20 AMoffer
to add jobRohit Surwase
11/01/2018, 5:21 AMgildor
11/01/2018, 5:21 AMit creates own handler_looper for that serviceYes, but you don’t need this with coroutines, because they provide own abstraction for cross-thread communication
Rohit Surwase
11/01/2018, 5:23 AMI don’t understand why you need runBlocking, just use buffered channel of infinity capacity and useOk, I will have a look into it.to add joboffer
gildor
11/01/2018, 5:24 AMgildor
11/01/2018, 5:26 AMrunBlocking would work if we are doing really small workBig issue in this case, that send potentially can suspend forever, not in your case because you have Channel.UNLIMITED, but what if handlerActor implementation will change
Rohit Surwase
11/01/2018, 5:26 AMonCompletion: CompletionHandler?
for Actorsgildor
11/01/2018, 5:27 AMchannel.invokeOnCompletion
instead. What is your actual problem?Rohit Surwase
11/01/2018, 5:28 AMjob.cancel() and stopSelf()
on actor completion.gildor
11/01/2018, 5:29 AMproduce{}.invokeOnCompletion { stopSelf() }
gildor
11/01/2018, 5:31 AMoverride val coroutineContext: CoroutineContext = <http://Dispatchers.IO|Dispatchers.IO> + Job()
Rohit Surwase
11/01/2018, 5:32 AMgildor
11/01/2018, 5:33 AMinvokeOnCompletion
not to channel, but to your scope JobRohit Surwase
11/01/2018, 5:42 AMit creates own handler_looper for that service
Yes, but you don’t need this with coroutines, because they provide own abstraction for cross-thread communicationDoes this mean even if we use only
Dispatchers.Main
our blocking code will not block main thread? If yes then on which thread our blocking code executes?gildor
11/01/2018, 5:44 AMgildor
11/01/2018, 5:44 AMgildor
11/01/2018, 5:44 AMRohit Surwase
11/01/2018, 5:45 AMrunBlocking
in onStartCommand
as handlerActor.send(msg)
is not allowed without Coroutines
.gildor
11/01/2018, 5:46 AMuseto add joboffer
Rohit Surwase
11/01/2018, 5:47 AMgildor
11/01/2018, 5:47 AMRohit Surwase
11/01/2018, 5:50 AMgildor
11/01/2018, 5:52 AMRohit Surwase
11/01/2018, 5:56 AMgildor
11/01/2018, 5:57 AMRohit Surwase
11/01/2018, 5:58 AM