5,064 questions
Best practices
2
votes
0
replies
25
views
Testing with corroutines
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 ...
-2
votes
0
answers
86
views
How to create horizontally scrolling category chips in Jetpack Compose like this UI? [closed]
I am trying to build a horizontally scrolling list of category chips in Jetpack Compose, similar to this design:
I want the categories to:
scroll horizontally
look like rounded chips
highlight the ...
4
votes
2
answers
148
views
How to call a composable function after a certain time in Jetpack Compose?
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 ...
0
votes
0
answers
26
views
Use suspend function with Vert.x Kafka Consumer?
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 ...
2
votes
0
answers
190
views
Objectify with Kotlin Ktor 3.3
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. ...
0
votes
3
answers
146
views
Are there any real difference between GlobalScope and CoroutineScope?
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 ...
2
votes
1
answer
88
views
How can I tie a coroutine's lifetime to the lifetime of an object?
I have some code similar to this:
class Foo {
var x = 0
init {
GlobalScope.launch {
while (true) {
delay(1000)
x += 1
}...
0
votes
1
answer
37
views
Creating activity prevents spinner from spinning in Android
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, ...
1
vote
2
answers
172
views
Testing a function that creates a coroutine scope inside it
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()
...
0
votes
1
answer
71
views
Jetpack Compose `LazyColumn takes` ~3 to ~4seconds to reflect `mutableStateListOf` mutations even though `Flow` emits immediately [closed]
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 ...
0
votes
1
answer
97
views
Why does Android prohibit running IO-performing coroutines from the main thread? [closed]
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....
0
votes
1
answer
59
views
SharedFlow emmited in another scope in a separated class is not collected
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 ...
0
votes
1
answer
97
views
Problems with Ktor receiving multipart: Flow invariant is violated
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") {
...
2
votes
1
answer
244
views
Kotlin' coroutines and retrofit2: Program blocks for one minute after getting http response
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 ...
0
votes
1
answer
41
views
error handling and Structured concurrency in corutin
i have this code my viewmodel init
val scope = CoroutineScope(Dispatchers.Main )
var child1:Job = Job()
var child2 : Deferred<Unit> = CompletableDeferred(Unit)
child1 =scope....
0
votes
1
answer
101
views
Ktor/Exposed TransactionManager.currentOrNull() not null after closing newSuspendedTransaction block when block contains delay()
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....
-1
votes
2
answers
160
views
Unit testing a broadcast receiver with callbackflow
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,
...
1
vote
2
answers
217
views
How to unit test a withtimeout block
I have this block:
try {
withTimeout(200) {
val response = datafetcher.fetchData(request)
}
} catch (TimeoutCancellationException e) {
returns response with some error message added
}
I am ...
0
votes
1
answer
36
views
Why does this code crash when i am passing the scope created from viewmodelScope which is a supervisorScope?
// code inside viewModel
viewModelScope.launch(Dispatchers.IO) {
try {
tempUsecase.coroutineTest(
coroutineScope = this,
)
} catch (e: Exception) {
...
1
vote
1
answer
79
views
How do you test code that uses withTimeout?
I have a code that uses withTimeout as follows.
suspend fun send(timeoutMillis: Long): Int? {
val result: Int? = withTimeoutOrNull(timeoutMillis) {
doSomething()
}
return result
}
suspend ...
2
votes
1
answer
187
views
Why is CoroutineContext element null via kotlin.coroutines.coroutineContext in tests (Kotest/Dispatchers.Default) but not production?
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 ...
0
votes
1
answer
75
views
Managing sequential callbacks with Kotlin
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, ...
0
votes
1
answer
256
views
How to update UI state using stateIn in ViewModel jetpack compose
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 ...
1
vote
0
answers
55
views
Some coroutines shenanigans in a custom flow operator with select clause
I have the following flow operator:
fun <T> Flow<T>.bufferedWithTimeout(
maxBufferSize: Int,
timeout: Duration
): Flow<List<T>> {
require(maxBufferSize > 0) {
&...
1
vote
1
answer
91
views
ConflatedBufferedChannel onUndeliveredElement behavior
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1
ConflatedBufferedChannel with capacity = 1.
If onBufferOverflow is configured as BufferOverflow.DROP_OLDEST
trySend returns success.
...