dave08
09/19/2019, 1:44 PMAlexjok
09/19/2019, 7:01 PMJustin Slade
09/20/2019, 9:57 AMDariusz Kuc
09/20/2019, 3:14 PMSeri
09/20/2019, 9:28 PM*.also {}
function that takes a suspending block of code?Tuan Kiet
09/21/2019, 8:58 AMscope.launch(<http://Dispatchers.IO|Dispatchers.IO>) {
doSomeWork() // take 1 second
}
does using coroutine create memory footprint? because it has to use Thread
at some point right? If I just launch 1 coroutine at the beginning and my app stay alive for 3 hours, does that Thread
stay in memory for 3 hours?darkmoon_uk
09/24/2019, 3:03 AMFlow
equivalent to Rx Merge ? http://reactivex.io/documentation/operators/merge.htmlPaul Woitaschek
09/24/2019, 6:40 AMFlow<Int>
. If it doesn't emit anything within 200ms, emit 0
?nitrog42
09/24/2019, 8:18 AMsuspend fun mappingFunction(dataToMap: List<String>) {
val mappedData = dataToMap.map {
}
// run suspendable work with mappedData
}
darkmoon_uk
09/24/2019, 1:28 PMflatMapLatest
isn't behaving as we expect; expectation is it should be dropping the ongoing Flow when a new element is processed, like Rx switchMap
sdeleuze
09/24/2019, 2:46 PMprivate
property with a suspending function return value (suspending supplier, pretty common when dealing with network)? Should I use lateinit var
? Nullable var
? Is something like suspend init { }
planned at some point?ansman
09/24/2019, 3:07 PMObservable -> Flow
in the Flow RX extensions? You can do Observable -> Flowable -> Flow
but it would be nice to be able to do convert it directlyreik.schatz
09/25/2019, 7:39 AMFlow
. How do I map from a Flow
to a nullable instance that my suspend function returns? In Reactor there are functions to map a Flux
to a Mono
..gmaciel
09/25/2019, 8:28 AMkotlinx.coroutines.rx2
? I'm wondering if i use rxSingle
, do i really need a context?
* Creates cold [single][Single] that will run a given [block] in a coroutine.
* Every time the returned observable is subscribed, it starts a new coroutine.
* Coroutine returns a single value. Unsubscribing cancels running coroutine.
Feels like as long i subscribes and unsubscribe in the right times it takes care of the coroutine and it doesn't cause memory leaks. Like this:
private fun single() = rxSingle {
suspendedFun()
}
Is this correct to assume? I also can't provide a Context with a job to cancel it anyways.uli
09/26/2019, 10:55 AMYoav Gross
09/26/2019, 12:12 PMuli
09/26/2019, 7:34 PMCoroutineScope
to Android lifecycles with a pattern like that:
class UiLifecycleScope : CoroutineScope, LifecycleObserver {
private lateinit var job: Job
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onCreate() {
job = Job()
}
Do you guys see any reason for constructing the context with a getter, creating a new context every time.
How about making the scope var
?
override lateinit var coroutineContext: CoroutineContext
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun onCreate() {
coroutineContext = Dispatchers.Main + Job()
}
JoakimForslund
09/27/2019, 10:06 AMrunBlocking(Dispatchers.Main) {}
be the same as running Handler(Looper.getMainLooper()).post{}
on android?Dennis Schröder
09/27/2019, 4:16 PMlaunch(newSingleThreadContext("ServiceContext")) {
...
}
and
launch {
withContext((newSingleThreadContext("ServiceContext") {
....
}
}
?xenoterracide
09/27/2019, 10:01 PMTash
09/28/2019, 5:35 AMnotify(...)
on an object of that class and it internally, with back-pressure awareness, processes and runs some computations on each notification.
This is on Android, and for this example creating an appScope
by using GlobalScope + CoroutineExceptionHandler
because I want to treat the processing of the notifications as “fire-and-forget”. Also trying to use consumeAsFlow()
+ collect()
on the Channel:
class ChannelExample {
private val appScope = GlobalScope + CoroutineExceptionHandler { coroutineContext, throwable ->
// Log message + throwable
}
private val numbersChannel = Channel<Int>()
init {
appScope.launch(Dispatchers.Default) {
numbersChannel
.consumeAsFlow()
.collect { number -> handleNumber(number)}
}
}
fun notifyNumber(number: Int) {
appScope.launch {
numbersChannel.send(number)
}
}
private suspend fun handleNumber(number: Int) {
try {
// Do some computations
} catch (ce: CancellationException) {
throw ce
} catch (ex: Exception) {
// Log message + exception
}
}
}
1) do I need to call close()
or cancel()
on numbersChannel
?
- if yes, where would be the best place to do that?
- if no, why not?
2) are there any other things in this example that stray from best practices?
3) are there better ways to achieve my original use case?
Thanks!scottiedog45
09/28/2019, 5:05 PMfun getInvoice(id: String) {
launchWithErrorHandling {
val invoice = repository.getInvoice(id)
_showSuccess.postValue(invoice)
}
}
Pablichjenkov
09/29/2019, 12:17 AMursus
09/29/2019, 6:05 AMursus
09/30/2019, 5:59 AMylemoigne
09/30/2019, 7:46 AMchannelFlow
, and a simple flow created with flowOf
. I want to concatenate them so I do val concatened = chanFlow.onCompletion { if(it==null) emitAll(simpleFlow) }
. Then the flow is "launched" GlobalScope.launch { concatened.collect { ... } }
. When I cancel the resulting job, the chanFlow stop correctly and throw CancellationException
, but the second flow values are still collected. The throwable
in onCompletion
is null. What is the correct way to handle this ?ursus
09/30/2019, 8:03 PMmyanmarking
10/01/2019, 10:57 AMmyanmarking
10/01/2019, 11:31 AM.asFlow
?myanmarking
10/01/2019, 11:43 AMmyanmarking
10/01/2019, 11:43 AMstreetsofboston
10/01/2019, 12:40 PM