Vincent Williams
07/29/2020, 10:07 PMval job = SupervisorJob()
val lifecycleScope = CoroutineScope(Dispatchers.Main + job)
lifecycleScope.launch { }
val job = SupervisorJob()
val lifecycleScope = CoroutineScope(job)
lifecycleScope.launch(Dispatchers.Main) { }
camdenorrb
07/30/2020, 12:07 AMDarren Gu
07/30/2020, 7:00 PMfun main() = runBlocking {
test()
}
suspend fun test() {
val job = coroutineScope {
launch {
delay(5000)
}
}
println("job = $job")
}
I need to have a reference to the job when it’s running. But the print doesn’t seem to execute until 5 sec later. What would be the correct way to achieve this?Santiago Laport
07/30/2020, 9:53 PMfun method(){
viewModelScope.launch {
val result1 = getSomeData1()
val result2 = getSomeData2()
val result3= getSomeData3()
...
}
}
suspend fun getSomeData1() : String? = suspendCoroutine { continuation ->
someInstance.addListener(SomeListener {
continuation.resume(data)
})
}
...
First time works well, but sometimes I need to execute again and I get the next exception:
IllegalStateException : Already resumed
this occurs in in the continuation.resume
rkeazor
07/31/2020, 3:08 AMColton Idle
07/31/2020, 7:50 AMorg.jetbrains.kotlinx:kotlinx-coroutines-core
but I don't see an 1.4-rc artifact on jfrog. Am I missing something?Eric Ampire [MOD]
07/31/2020, 11:08 AMasad.awadia
07/31/2020, 1:02 PMfun main() {
val apiRequest = 1
var apiResponse = ""
runBlocking {
apiResponse = withContext(<http://Dispatchers.IO|Dispatchers.IO>) { someApiCallThatReturns(apiRequest) }
}
}
is ‘returning responses’/‘sending arguments’ responses from one thread/coroutines on different didspatchers to another like this safe to do?Nikky
07/31/2020, 3:59 PMsuspend fun
?zak.taccardi
07/31/2020, 4:54 PMwithContext(EmptyCoroutineContext) { .. }
basically does nothing right?Sam Garfinkel
07/31/2020, 4:56 PMdoSomething()
in this snippet prevents the outer run()
loop from continuing? You’ll notice that "Continuing to run"
is printed after "doSomething with $hello done"
which is the opposite pattern I’m looking for.iseki
07/31/2020, 11:05 PMsuspendCancellableCoroutine
is experiment but suspendCoroutine
is not?Gopal S Akshintala
08/02/2020, 1:09 PMList<A>
and a fn suspend (A) -> B
, how can I apply this fn on the list in parallel?Lukas Lechner
08/03/2020, 7:34 AMJob()
object to launch
or async
? For most use cases, its better to launch them in another scope or use superVisorScope{}
if you want to use SupervisorJob
, right?rmyhal
08/03/2020, 1:11 PMandylamax
08/03/2020, 1:17 PMcoroutines-native-mt
) being passed around. May someone please explain to me what it is and its difference to coroutines-native
?jenji
08/03/2020, 5:48 PMKoya Sivaji
08/03/2020, 9:50 PMDeviceDao{
@Query("SELECT * FROM devices")
abstract fun getAllDevices(): Flow<List<Device>>
}
Repository layer
fun getAllDevices() = database.deviceDao().getAllDevices()
This repository method called form view model as below and every thing works fine
viewModelScope.launch {
homes = homeRepository.homes.asLiveData()
devices = deviceRepository.getAllDevices().asLiveData()
}
Issue I am facing:
Added another method at repository layer like below
private suspend fun deleteDevicesNotInLambdaResponse(deviceJsonList: List<Device>) {
var localDevices = emptyList<Device>()
database.deviceDao().getAllDevices().collect {
localDevices = it
}
//. the below code never executes
val localDeviceIds = localDevices.map { it.deviceId }
val remoteDeviceIds = deviceJsonList.map { it.deviceId }
val localDevicesNotInLambdaResponse = localDeviceIds.filterNot { remoteDeviceIds.contains(it) }
database.deviceDao().deleteDevices(localDevicesNotInLambdaResponse)
}
Basically, here I want to get all local devices and find out which are not in API response and delete those devices from local data base
As commented above, the code below the comment the below code never executes
got never executed.
Looks like I am missing some thing about how the Flow operator works
Please suggest me how to fix this issueLukas Lechner
08/04/2020, 9:14 AMlifecycleScope
? IMO most (all?) coroutines should be started in viewModelScope
because then they continue to run on orientation changes.Erik
08/04/2020, 9:56 AMvalue
of a MutableStateFlow
from multiple threads? I guess it is, but then it is unknown which of the setters set the last value (which is also the last one collected/got from value
)? The StateFlow
docs mention 'All methods of data flow are thread-safe and can be safely invoked from concurrent coroutines without external synchronization', but does this include the value
setter and getter? Seems unlikely to me.Erik
08/04/2020, 10:04 AMMutableStateFlow.value
read-and-write operation? I mean: first read the current value
(this is thread-unsafe, because I don't know if another thread will change the value just after I read it), then use it to set it again. I can probably use a Channel
for this, but how do I do this? And there are probably alternatives?George Theocharis
08/04/2020, 10:48 AMGeorge Theocharis
08/04/2020, 3:47 PMmutableStateFlow.asLiveData()
is pretty much best of both worlds as you can have access to the operators privately while exposing a lifecycle aware state? Is there any huge pitfall I haven’t think of?trevjones
08/04/2020, 8:27 PMcombine(one, two, three) { 1, 2, 3 -> Triple(1,2,3) }.flatMapLatest { (1, 2, 3) -> ... }
is there a cleaner way built in to deal with that?Lukas Lechner
08/05/2020, 6:55 AM.cancel()
on the job of the scope VS calling .cancel()
on the scope itself? Lots of blogpost recommend to keep a reference to the job
in order to be able to cancel it, although IMO this is not necessary, as cancelling the scope itself has the exact same effect. Am I correct?Sudhir Singh Khanger
08/05/2020, 9:26 AMmap
operator here.
Where should I do this accessory work? In the repository before the values are emitted or in the UI where the data is delivered. Or if there is another operator that let's me do such accessory work.Sam Garfinkel
08/05/2020, 2:44 PMInputStream
in a flow { }
builder? Getting warnings from IntelliJ about inappropriate blocking calls.dan.the.man
08/05/2020, 3:27 PMcoroutinesTestRule.testDispatcher.runBlockingTest {
var latestNav: NavEvent? = null
navChannel.consumeEach {
latestNav = it }
vm.handleAction(NearbyListingClicked(nearbyListing))
assertEquals(latestNav, OpenListing(variant.listing!!.wmid.toString()))
}
But I'm just getting java.lang.IllegalStateException: This job has not completed yet
The Channel.consumeEach
appears to be blocking, which I don't think it should beMarc Knaup
08/05/2020, 4:37 PMokue
08/07/2020, 4:59 AMMono#awaitFirst()
is executed, BlockHound detected blocking call here:
https://github.com/Kotlin/kotlinx.coroutines/blob/1.3.8/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt#L145
Off course, this detection occurs only once or twice after starting my application.
After contextInjector
is initialized, this detection is not warned any more.
Though this is not so a severe problem, I want to know a good way to suppress this error.
It would be happy if kotlinx.coroutines BlockHound integration resolves this issue.okue
08/07/2020, 4:59 AMMono#awaitFirst()
is executed, BlockHound detected blocking call here:
https://github.com/Kotlin/kotlinx.coroutines/blob/1.3.8/reactive/kotlinx-coroutines-reactive/src/ReactiveFlow.kt#L145
Off course, this detection occurs only once or twice after starting my application.
After contextInjector
is initialized, this detection is not warned any more.
Though this is not so a severe problem, I want to know a good way to suppress this error.
It would be happy if kotlinx.coroutines BlockHound integration resolves this issue.Erik
08/07/2020, 10:38 AMokue
08/11/2020, 8:58 AM