Vsevolod Ganin
01/31/2020, 1:16 PMw: Experimental API marker kotlinx.coroutines.FlowPreview is unresolved. Please make sure it's present in the module dependencies
. I’m using allWarningsAsErrors = true
so this stops my build. Is there any way to suppress this warning with compiler flag?antoniomarin
01/31/2020, 2:13 PMUseCase
, I guess flow
should be used?audriusk
01/31/2020, 3:57 PM@Test
fun someTest() = runBlockingTest {
Dispatchers.setMain(coroutineContext[ContinuationInterceptor] as CoroutineDispatcher)
val viewModel = arrange()
viewModel.viewModelScope.launch {
throw IllegalStateException("mm")
}
}
From my understanding problem is viewModelScope
extension which creates SupervisorJob
at https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:lifecycle/lifecycle-viewmodel-ktx/src/main/java/androidx/lifecycle/ViewModel.kt;l=42;drc=9f40e609cef60d1889e2b13d48ba1dbb8aa345e3
What would be appropriate way to make such test method fail?dimsuz
01/31/2020, 4:36 PMsend
is a suspending function and as such not usable from Swift/ObjC.
Are there docs about this which I've missed?
I see a lot of tutorials for iOS concurrency, but a little about this kind of interop.
Not sure if this is the right channel as it is both about #coroutines and #multiplatformJabez Magomere
02/03/2020, 1:31 PMArkadii Ivanov
02/03/2020, 10:27 PMBroadcastChannel
drops items if there are no subscribers. Is there a way to not drop but buffer? Looking for something with UnicastSubject
behaviour.Derek Berner
02/03/2020, 10:44 PMkotlinx-coroutines-io
as a dependency to the commonMain
sourceset in a MPP project?Abhishek Bansal
02/04/2020, 10:12 AMBroadcastChannel#openSubscription.consumeAsFlow()
completes when collected? If not how do I go about cancelling subscription?
I was trying to do this in my class so that client does not have to worry about cancelling the subscription
private fun getResponseChannel(): Flow<ContentResponse> {
val channel = responseChannel.openSubscription()
return channel
.consumeAsFlow()
.onCompletion {
Timber.d("Cancelled")
channel.cancel()
}
}
But it seems that onCompletion
never gets calledmyanmarking
02/04/2020, 10:44 AMgotoOla
02/04/2020, 2:57 PMJabez Magomere
02/05/2020, 6:43 AMfatih
02/05/2020, 9:43 AMFlow
on device rotation in Android if you are only using Flow
(without LiveData
)? I see that Dropbox Store library caches the latest and provides when it is requested again. https://github.com/dropbox/Store
The first time you call to suspend store.get(key), the response will be stored in an in-memory cache and in the persister, if provided. All subsequent calls to store.get(key) with the same Key will retrieve the cached version of the data, minimizing unnecessary data calls.
Since the Flow is cold it is going to be collected evertime.Slackbot
02/05/2020, 10:25 AMdimsuz
02/05/2020, 12:25 PMclass MyClass : CoroutineScope by MainScope() {
fun execute() = launch {
delay(1000)
println("finished")
}
}
fun main() = runBlocking {
val clazz = MyClass()
clazz.execute()
}
This throws an exception:
kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
What do I do wrong?
• If MyClass is external and I can't modify it, how to solve this?
• For some reason if I run the code from the main()
function in Android Activity (which doesn't even have any CouroutineScope), it runs perfectly well. Why?myanmarking
02/05/2020, 3:23 PMdave08
02/05/2020, 4:57 PMFlow
without having to use toList().last()
...?Joe
02/05/2020, 7:41 PMclass CoroutineJob {
suspend fun doWork() {
// do stuff in coroutine context
}
}
// elsewhere:
scope.launch {
CoroutineJob().doWork()
)
or
class CoroutineJob(val scope: CoroutineScope) {
fun launchWork() {
scope.launch {
// do stuff in coroutine context (possibly calling another suspend fun member?)
}
}
}
// elsewhere:
CoroutineJob(scope).launchWork()
or something else?hiperbou
02/05/2020, 8:08 PMRemy Benza
02/06/2020, 8:00 AMdave08
02/06/2020, 5:25 PMBroadcastChannel
and I send something before using asFlow()
on it, will I receive what was sent?ubu
02/07/2020, 11:00 AMViewModel
, I had a basic MVI-inspired state machine implemented in the following way:
/**
* State machine for this view model consisting of [Interactor], [State], [Event] and [Reducer]
* It reduces [Event] to the immutable [State] by applying [Reducer] fuction.
* This [State] then will be rendered.
*/
class Interactor(
private val scope: CoroutineScope,
private val reducer: Reducer = Reducer(),
private val channel: Channel<Event> = Channel(),
private val events: Flow<Event> = channel.consumeAsFlow()
) {
fun onEvent(event: Event) = scope.launch { channel.send(event) }
fun state(): Flow<State> = events.scan(State.init(), reducer.function)
}
interface StateReducer<STATE, EVENT> {
val function: suspend (STATE, EVENT) -> STATE
suspend fun reduce(state: STATE, event: EVENT): STATE
}
But then I was unable to get current state, I could only observe it as a Flow<State>
, so I re-implemented it in the following manner:
class Interactor(
private val scope: CoroutineScope,
private val reducer: Reducer = Reducer(),
private val channel: Channel<Event> = Channel(),
private val events: Flow<Event> = channel.consumeAsFlow()
) {
val state = ConflatedBroadcastChannel<State>()
init {
scope.launch {
events.scan(State.init(), reducer.function).collect { state.send(it) }
}
}
fun onEvent(event: Event) = scope.launch { channel.send(event) }
fun state(): Flow<State> = state.asFlow()
}
I guess it could be improved. Are there any inherent problems to this implementation? Thanks a lot, in advance 💥.kevin.cianfarini
02/07/2020, 10:39 PMChannel.offer
on a RendezvousChannel
always return false? Or will it return true if a receiver is already waiting for the next value?Nikky
02/08/2020, 12:15 PMsame thread enforcement
of a library?
i need to store what thread something was created on and then switch back to it whenever interacting with it
i just nee the right keyword to look for, not even sure what to look forGabriel Feo
02/08/2020, 8:09 PMRobert
02/09/2020, 3:11 PMKonstantin Petrukhnov
02/10/2020, 7:34 AMkevin.cianfarini
02/10/2020, 3:53 PMchannelFlow
doesn't expose something like fun channelFlow(buffer: Int = ...)
And instead we have to call .buffer
downstream?kevin.cianfarini
02/10/2020, 3:56 PMkevin.cianfarini
02/10/2020, 4:13 PMgergo
02/10/2020, 4:22 PMsuspend fun
annotated with @Throws(IOException::class)
, then the IDE will signal an “Inapropiate blocking method call”, even if the called method runs on the IO dispatcher. Example:
suspend fun testCall(uri: Uri) {
val image = encodeImageToBase64(uri)
}
@Throws(IOException::class)
private suspend fun encodeImageToBase64(imageUri: Uri): String = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
// Do something
""
}
(Android Studio 3.6-rc02, kotlin version: 1.3.50/1.3.61)
I am not sure why this warning is shown in such case? Could this be a lint issue or am I missing something?gergo
02/10/2020, 4:22 PMsuspend fun
annotated with @Throws(IOException::class)
, then the IDE will signal an “Inapropiate blocking method call”, even if the called method runs on the IO dispatcher. Example:
suspend fun testCall(uri: Uri) {
val image = encodeImageToBase64(uri)
}
@Throws(IOException::class)
private suspend fun encodeImageToBase64(imageUri: Uri): String = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
// Do something
""
}
(Android Studio 3.6-rc02, kotlin version: 1.3.50/1.3.61)
I am not sure why this warning is shown in such case? Could this be a lint issue or am I missing something?Brandon Trautmann
02/10/2020, 4:37 PMKroppeb
02/10/2020, 11:09 PM