Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
77 views

Why does this code block indefinitely? fun main() = runBlocking { val myFlow: Flow<String> = flow { emit("abc") }.flowOn(Dispatchers.Main) myFlow.collect { ...
Shaman4562's user avatar
0 votes
1 answer
152 views

In our project we are observing an issue with consuming the data from MutableSharedFlow. Under certain conditions we are cancelling the scope in which we produce and collect data. Then we launch data ...
Anton K's user avatar
Best practices
3 votes
0 replies
40 views

Let's say I have Worker class and I want to do long running tasks in the background until user stops it or it is cancelled. It changes state of the class while doing the work and I want to write tests ...
Domz's user avatar
  • 11
4 votes
1 answer
105 views

When I use combine() on two flow, it's not supposed to conflate/skip values. But when I collect a combine of 2 flows in a Coroutine, some values are randomly skipped. Link to the kotlin playground : ...
Benjamin K's user avatar
0 votes
2 answers
62 views

I am trying to test the number of times a Flow is collected - runTest { var count = 0 backgroundScope.launch(UnconfinedTestDispatcher(testScheduler)) { dao.getEntities().collect { ...
jL4's user avatar
  • 1,242
4 votes
2 answers
162 views

When my application starts, I launch an animation. Now I would like to switch to another component (navbar) after 30 seconds. In my research, I saw that the delay function from the Kotlin Coroutines ...
Yann Djomo's user avatar
0 votes
0 answers
73 views

I’ve read in multiple places that async can swallow exceptions if we don’t call await, but as far as I can see, it almost always throws them regardless of whether await is used or not. For example, ...
Prexi's user avatar
  • 13
0 votes
0 answers
31 views

I want to use suspend function in a handler for KafkaConsumer. This is what I have so far, but I'm not sure about exception handling. CoroutineEventBusSupport would call fail() on the message and ...
Jakub Bochenski's user avatar
-2 votes
2 answers
130 views

I have an Activity that is responsible for creating a new entry in the database. In this activity, a button launches a coroutine to do all the database-related stuff, and when it's done, navigate to ...
Wladyslaw Skiba's user avatar
3 votes
0 answers
194 views

Objectify v6.1.3 With Kotlin and Ktor 3.1, I was calling ObjectifyService.begin() within the init {} block of my request handler base class and then closing that context once the request was finished. ...
Brian White's user avatar
  • 8,864
1 vote
1 answer
87 views

I have a data stream coming from the server. The server does not provide any information about when the next piece of data will arrive. I have a Flow in my repository that emits data as it arrives. ...
Vivek Modi's user avatar
  • 7,869
0 votes
3 answers
152 views

I'm trying to understand the difference between the 2. If a CoroutineScope is not tied to any lifecycle-aware component, then I think they behave the same: If Im not passing any context to ...
Prexi's user avatar
  • 13
0 votes
1 answer
66 views

I've read this sentence in the Java Concurrency in Practice book that: The result of Thread.getState should not be used for concurrency control, and is of limited usefulness for testing—its primary ...
Mohammadreza Khahani's user avatar
2 votes
1 answer
96 views

I have some code similar to this: class Foo { var x = 0 init { GlobalScope.launch { while (true) { delay(1000) x += 1 }...
Seggan's user avatar
  • 216
0 votes
1 answer
185 views

I have a code base which is tightly coupled with BoradcastChannel and I can't update that for now. But I want to upgrade the dependencies to their latest, use kotlin2 and compose. I have changed my ...
msc87's user avatar
  • 1,047
0 votes
1 answer
39 views

I have 2 activities in my app. When another one is called there is a spinner but it doesn't spin. I think it may be because the main thread is stuck. I moved all background tasks to Dispatchers.IO, ...
EnergyKickman's user avatar
5 votes
0 answers
153 views

The action parameter of the withLock function is a lambda without the suspend keyword. Is there a reason for this missing keyword? In most cases, this lack of the suspend keyword isn't an issue ...
AndroidKotlinNoob's user avatar
1 vote
2 answers
187 views

I have something like the following in Kotlin: class A { fun a(): Unit = TODO() } fun foo(a: A) { // Do something CoroutineScope(Dispatchers.IO).launch { delay(1000) a.a() ...
riccardo.cardin's user avatar
2 votes
2 answers
102 views

Consider the following Kotlin object: package com.example import org.slf4j.LoggerFactory import java.lang.Thread.currentThread import kotlinx.coroutines.Dispatchers import kotlinx.coroutines....
Андрей Щеглов's user avatar
0 votes
1 answer
72 views

I switch between “chart windows” (weekly, monthly…). Upstream data is a hot Flow (think Room). To keep the list size stable, I render 30 fixed slots: real items in the first n, placeholders in the ...
Klem Lloyd Mwenya's user avatar
2 votes
1 answer
65 views

I am working on a program which has both a TUI (terminal user interface) as well as a GUI (graphical user interface). The program has some functions which take quite a long time to complete (waiting ...
Whirvis's user avatar
  • 356
0 votes
1 answer
107 views

Context and prior understanding: In Node.JS, I/O code is run in a thread pool / event loop parallel to the main JavaScript thread. async code is never truly blocking per-se, unless a blocking call (e....
anon's user avatar
  • 697
2 votes
1 answer
74 views

Why the output of this code is so unpredictable? suspend fun main() { val job1 = GlobalScope.launch { delay(1000L) println("World!") } val job2 = GlobalScope....
Kumar Atul's user avatar
0 votes
1 answer
62 views

I have a Bluetooth tracker app. I try it to be clean. Everything related to scan is encapsulated in one class. I am injecting with Hilt. The problem is when I scan via Bluetooth for 10s, I emit the ...
sepideh's user avatar
  • 59
0 votes
0 answers
44 views

I have a spring web flux based application, written in kotlin I am adding few information in reactor context by using web filter. I also have logging information which I set in MDCContext but I am ...
Abhishek kapoor's user avatar
0 votes
1 answer
110 views

I am rather new to Ktor and try to upload a file to my server. This is the route: fun Application.module() { install(ContentNegotiation) { json() } routing { post("/upload") { ...
KCD's user avatar
  • 698
1 vote
1 answer
68 views

So, I am aware of the fact that in Android, views cannot be updated from a background thread. I have a TextView called appTitle. I am launching a coroutine on background thread ( IO ) and on that ...
stardep's user avatar
  • 300
2 votes
1 answer
244 views

I need to use Kotlin' coroutines and the retrofit2 library to make http requests. When I run the following code, the http request works as expected (posts is printed), but after this, the program ...
Berk7871's user avatar
  • 293
1 vote
1 answer
63 views

I am using the MVVM model and have come across a problem with Stateflow that I cannot find a solution. Perhaps I am approaching the problem in the wrong way. Each of my Models responds to a specific ...
SMBiggs's user avatar
  • 11.8k
0 votes
1 answer
42 views

i have this code my viewmodel init val scope = CoroutineScope(Dispatchers.Main ) var child1:Job = Job() var child2 : Deferred<Unit> = CompletableDeferred(Unit) child1 =scope....
sepideh's user avatar
  • 59
1 vote
0 answers
143 views

Problem I'm using Spring Boot 3.3.3 with Spring Security and Kotlin coroutines. My authentication filter successfully authenticates the user and sets the SecurityContext, but when I use suspend fun in ...
dzmoxn's user avatar
  • 48
0 votes
1 answer
117 views

I’m looking for some insight into this issue I’m having with my Ktor/exposed application… If I do the following in a KTOR route, after the newSuspendedTransaction block is closed, TransactionManager....
prule's user avatar
  • 2,584
2 votes
2 answers
109 views

These code is from a Udemy-course, which I'm following currently: fun getWeatherData() { viewModelScope.launch(exceptionHandler) { uiState = try { val ...
mewi's user avatar
  • 791
-1 votes
2 answers
161 views

I have the following class I am trying to test. I am using mockito as that is the library I am using class ConsentUpdatedBroadcastReceiverImp @Inject constructor( private val context: Context, ...
ant2009's user avatar
  • 22.7k
1 vote
1 answer
109 views

I have the following BroadCastReceiver. I inject a 3rd party library and have to call a method on it to get a result each time the onReceive is called. I need to observe this changes from our ...
ant2009's user avatar
  • 22.7k
1 vote
2 answers
239 views

I have this block: try { withTimeout(200) { val response = datafetcher.fetchData(request) } } catch (TimeoutCancellationException e) { returns response with some error message added } I am ...
mulafar p's user avatar
0 votes
1 answer
59 views

I need to return a Flow<List<MyEntity<>> from Room @RawQuery in Compose but get runtime error: Cannot access database on the main thread. I have found many posts for @Query about using ...
jetberrocal's user avatar
0 votes
1 answer
46 views

// code inside viewModel viewModelScope.launch(Dispatchers.IO) { try { tempUsecase.coroutineTest( coroutineScope = this, ) } catch (e: Exception) { ...
Learner_Android's user avatar
0 votes
1 answer
101 views

So, i have a composable, a viewmodel and a repository. I am fetching data from Firebase's Firestore, and it already has some documents in the collection i am fetching from. These are the snippets of: ...
Avdhoot Gole's user avatar
1 vote
1 answer
84 views

I have a code that uses withTimeout as follows. suspend fun send(timeoutMillis: Long): Int? { val result: Int? = withTimeoutOrNull(timeoutMillis) { doSomething() } return result } suspend ...
SpeedRacer's user avatar
0 votes
1 answer
22 views

I have suspending function, which returns a hot flow. suspend fun createFlow(): SharedFlow How can I build another SharedFlow, which calls createFlow lazily (i.e. as only first subscriber connects to ...
Alexey's user avatar
  • 3,202
2 votes
1 answer
198 views

I'm encountering a discrepancy in retrieving a custom CoroutineContext.Element (TraceContextElement) depending on the environment (test vs. production) and how I access the context within a launched ...
happy_friend's user avatar
3 votes
2 answers
318 views

Came across an example that simulates accessing a slow database to obtain a flow of user identifiers which is associated with a profile that's accessible via an even slower network resource: fun ...
Ken Kiarie's user avatar
0 votes
1 answer
76 views

There is a very common pattern when dealing a remote service: A sequential series of calls to the service, each of which invokes a callback, asynchronously, when complete. I believe, for instance, ...
G. Blake Meike's user avatar
0 votes
2 answers
120 views

Goal I have a computation heavy function calculateItems: suspend (String) -> Sequence<String>. I want to load the outputs of this calculation while showing the progress to the user and ...
Gamer2015's user avatar
  • 341
0 votes
1 answer
288 views

I have a ProfileViewModel where I load the user profile when the user lands on the screen. To achieve this, I use stateIn so that the profile is fetched automatically. Now, I want to modify ...
Vivek Modi's user avatar
  • 7,869
1 vote
1 answer
130 views

I have function like this fun getUsersList(userIds: List<String>): List<User> { val list = mutableListOf<User>() userIds.forEach { id -> getUserFromDatabase(id) {...
Exicode's user avatar
  • 137
1 vote
0 answers
59 views

I have the following flow operator: fun <T> Flow<T>.bufferedWithTimeout( maxBufferSize: Int, timeout: Duration ): Flow<List<T>> { require(maxBufferSize > 0) { &...
Calamity's user avatar
  • 1,060
0 votes
1 answer
173 views

I’m working with a regular CoroutineScope (not a supervisorScope). I’ve noticed that when I launch an async block inside this scope, and it throws an exception—even if that exception is caught outside ...
user3612643's user avatar
  • 6,040
1 vote
1 answer
100 views

org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1 ConflatedBufferedChannel with capacity = 1. If onBufferOverflow is configured as BufferOverflow.DROP_OLDEST trySend returns success. ...
toffor's user avatar
  • 1,309

1
2 3 4 5
102