Questions tagged [coroutinescope]
The coroutinescope tag has no usage guidance.
coroutinescope
148
questions
1
vote
1
answer
36
views
Kotlin execution order mix with different scope and coroutines
I'm trying to figure out the order of the execution of coroutine. Here is my example.
fun theCoroutineOrderWithDifferentScope() = runBlocking {
coroutineScope {
println("in the ...
1
vote
2
answers
42
views
What is the difference when we call withContext with coroutineContext and Job?
I am confused about working with withContext in Coroutine. I was calling withContext in a suspend function with the IO dispatcher. In that case, in some situations, the coroutine is canceled because ...
1
vote
1
answer
30
views
Ktor: launch long-running task then immediately send HTTP response
How do I properly launch a long-running task in Ktor sever without waiting for its completion, i.e.
launch and immediately send the HTTP response back.
In this answer: https://stackoverflow.com/a/...
0
votes
1
answer
313
views
Use coroutine scope in a kotlin suspend function
I need to write a Kotlin suspending function which does the following:
Launches a cancellable infinite operation, like collecting a flow or running a while cycle which generates flow values.
After ...
1
vote
3
answers
408
views
viewModelScope.launch and main thread ANR issue?
As per As per Android Developer doc
viewModelScope.launch Create a new coroutine on the UI thread and code is as below
class LoginViewModel(
private val loginRepository: LoginRepository
): ViewModel()...
0
votes
0
answers
50
views
Coroutines. How to launch parallel coroutine?
I need to make 3 parallel request. And I need an exception for one request not to block or cancel the execution of another coroutine except for only one type of exception.
Here is my code:
...
0
votes
1
answer
291
views
Coroutine launch not waiting with StandardTestDispatcher
I’ve a ViewModel that has a viewModelScope.launch{} on the init{}. I’m trying to run a test where I set Dispatchers.setMain(StandardTestDispatcher()) but the launch{} is running before I call ...
0
votes
1
answer
168
views
Kotlin: would a coroutine job be cleaned up automatically when complete?
Basically what the title says. The only additional question is that if the job is not cleaned up, would those jobs be additional overhead if we keep reusing the same parent scope to create new ...
1
vote
1
answer
784
views
How can I call multiple APIs that are depending to each other's data, each response data must be used on the following API call?
//From Kotlin code (Compose View), using CoroutineScope
scope.launch {
viewModel.getDataOne(key)
viewModel.data_one.collect{ one ->
when(one){
is DataState.Success->{
...
0
votes
1
answer
290
views
Calling a coroutine on Dispatchers.IO (for saving Api results) inside a coroutine running (for Api call) on Dispatchers.IO to simulate a threadpool
I have a usecase where I want to save to a database after making an API call. I want to do all of this in a single operator/invokee function.
One option is to create a custom coroutine context and ...
0
votes
1
answer
260
views
Android. How to correctly use viewModelScope?
I'm trying to call 2 parallel task in my view model.
Here is my code:
fun init {
viewModelScope.launch(genericErrorHandler) {
launch {
interactor1.task()
// handle result here ...
0
votes
1
answer
1k
views
When to use lifecycleScope.launch {}
I'm not clear on when and why we need to use lifecycleScope.launch {}
I understand that this doesn't block the UI thread, but if you are doing UI work shouldn't you be doing it on the UIThread?
What ...
0
votes
1
answer
109
views
Error when user enable camera permission : java.lang.IllegalStateException: Method setCurrentState must be called on the main thread
I have an Activity which is a camera. In that activity, there is permission before using the camera, but there is a problem when the user allows the use of the camera, namely the application will ...
0
votes
1
answer
624
views
Kotlin mockk how to verify that method was called (in background scope)?
I'm trying to write test for my ViewModel method. Here is part of code from my ViewModel:
fun makeBackgroundCallAndClose() {
backgroundScope.launch(genericErrorHandler) {
...
0
votes
1
answer
722
views
Is it correct to use suspend fun that returns with context value inside another suspend fun that returns with context value?
At the moment I am using in my app suspend fun such as getSessionId(), getLocationLatitude(), getLocationLongitude(), getActionDateTime() and getUserName() which returns some values from the database ...