Kulwinder Singh
04/06/2018, 12:54 PMsecond
are in milliseconds
thats my mistake of wrong namingKulwinder Singh
04/06/2018, 12:55 PMdelay
we need to launch
new coroutine
?altavir
04/06/2018, 1:03 PMKulwinder Singh
04/06/2018, 1:04 PMUI
threadaltavir
04/06/2018, 1:10 PMlouiscad
04/06/2018, 6:43 PMConflatedBroadcastChannel<Boolean>
for that, or is this overkill and should I use something else?Sorin
04/06/2018, 7:51 PMbj0
04/06/2018, 9:22 PMSorin
04/07/2018, 12:22 PMSorin
04/07/2018, 12:23 PMSorin
04/07/2018, 12:23 PM/**
* You can use like this.
* val channel = EventBus().asChannel<ItemChangeAction>()
* launch (UI){
* for(action in channel){
* // You can use item
* action.item
* }
* }
*/
@Singleton
class EventBus @Inject constructor() {
val bus: BroadcastChannel<Any> = ConflatedBroadcastChannel()
fun send(o: Any) {
launch {
bus.send(o)
}
}
inline fun <reified T> asChannel(): ReceiveChannel<T> {
return bus.openSubscription().filter { it is T }.map { it as T }
}
}
Sorin
04/07/2018, 12:23 PMgroostav
04/09/2018, 9:42 AMuser
04/09/2018, 12:26 PMworker
for all those subsequent channels, I’d use coroutineContext
, since they were all launched within the worker
anyway
Finally, I’d replace the while(true)
with while(isActive)
groostav
04/09/2018, 10:15 PMmap
and filter
in mind when writing these but I couldn't find them, so i simply went with for-each loops. are these operators defined somewhere in kotlinx.coroutines
already?
your right, but my LiveThreadFactory.create()
stuff just adds to debugability, since it will wrap the ForkJoinPool (aka CommonPool on java7+) in some thread-renaming stuff. I played with the idea of aiming for something like launch(CommonPool + Renaming)
, but order-of-operations became an issue, and it also made for what I thought were odd lifecycles, so I just kept what is something of a convention already for me.
and while(true)
to while(isActive)
is an OK idea, but watchService actually throws something similar to ChannelIsClosedException
when you call watchService.close()
, so I've actually updated the above code to include a
try { while(true) send(take()) } catch(ex: CannotTakeException) { log.fine("watch service closed", ex) }
pakoito
04/09/2018, 10:30 PMI actually hadhttps://github.com/arrow-kt/arrow/blob/master/modules/effects/arrow-effects-kotlinx-coroutines/src/main/kotlin/arrow/effects/DeferredK.ktandmap
in mind when writing these but I couldn’t find them, so i simply went with for-each loops. are these operators defined somewhere infilter
already?kotlinx.coroutines
pakoito
04/09/2018, 10:30 PMgroostav
04/10/2018, 3:09 AMpakoito
04/10/2018, 10:24 AMpakoito
04/10/2018, 10:24 AMPaul Woitaschek
04/10/2018, 3:25 PMjohannes.lagos
04/11/2018, 11:35 AMjohannes.lagos
04/11/2018, 11:36 AMjohannes.lagos
04/11/2018, 11:37 AMjohannes.lagos
04/11/2018, 11:39 AMgildor
04/13/2018, 9:16 AMgildor
04/13/2018, 9:18 AMasync
with launch
if you don’t want to do something after those tasks (so you don’t care about await())louiscad
04/13/2018, 9:45 AMsuspend operator fun invoke()
on a companion object
is so neat!otakusenpai
04/14/2018, 6:05 PMotakusenpai
04/14/2018, 6:07 PM